Api hw gpio pwm (#199)
* initial gpio layer * move temlplate.c to template.c.example in preparing to applications.mk rework * separate arduino layer * separate flipper_hal.x * prepare to switch applications on v2 core gpio api * swithch applications to v2 gpio api * gpio api for local target * better gpio_disable handling * remove pwm functions from local target * inline gpio funcs * common function to init all api's * fix local example blink * move delay us to hal api folder * move pwm_set/pwm_stop to hal api folder * update applications to use hal pwm api * remove gpio mode case warning * add speaker demo to build Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
@@ -35,6 +35,10 @@ const FlipperStartupApp FLIPPER_STARTUP[] = {
|
||||
{.app = display_u8g2, .name = "display_u8g2", .libs = {0}},
|
||||
#endif
|
||||
|
||||
#ifdef APP_EXAMPLE_BLINK
|
||||
{.app = application_blink, .name = "blink", .libs = {0}},
|
||||
#endif
|
||||
|
||||
#ifdef APP_INPUT
|
||||
{.app = input_task, .name = "input_task", .libs = {0}},
|
||||
#endif
|
||||
@@ -61,8 +65,6 @@ const FlipperStartupApp FLIPPER_STARTUP[] = {
|
||||
{.app = nfc_task, .name = "nfc_task", .libs = {1, FURI_LIB{"menu_task"}}},
|
||||
#endif
|
||||
|
||||
// {.app = coreglitch_demo_0, .name = "coreglitch_demo_0", .libs = ""},
|
||||
|
||||
#ifdef APP_TEST
|
||||
{.app = flipper_test_app, .name = "test app", .libs = {0}},
|
||||
#endif
|
||||
@@ -83,6 +85,10 @@ const FlipperStartupApp FLIPPER_STARTUP[] = {
|
||||
#ifdef APP_EXAMPLE_DISPLAY
|
||||
{.app = u8g2_example, .name = "u8g2_example", .libs = {1, FURI_LIB{"display_u8g2"}}},
|
||||
#endif
|
||||
|
||||
#ifdef APP_SPEAKER_DEMO
|
||||
{.app = coreglitch_demo_0, .name = "coreglitch_demo_0", .libs = ""},
|
||||
#endif
|
||||
};
|
||||
|
||||
const FlipperStartupApp FLIPPER_APPS[] = {
|
||||
@@ -101,7 +107,12 @@ const FlipperStartupApp FLIPPER_APPS[] = {
|
||||
#ifdef BUILD_CC1101
|
||||
{.app = cc1101_workaround, .name = "cc1101 workaround", .libs = {1, FURI_LIB{"gui_task"}}},
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_IRDA
|
||||
{.app = irda, .name = "irda", .libs = {1, FURI_LIB{"gui_task"}}},
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_SPEAKER_DEMO
|
||||
{.app = coreglitch_demo_0, .name = "coreglitch_demo_0", .libs = {0}},
|
||||
#endif
|
||||
};
|
@@ -15,6 +15,7 @@ BUILD_EXAMPLE_BLINK = 1
|
||||
BUILD_EXAMPLE_UART_WRITE = 1
|
||||
BUILD_EXAMPLE_INPUT_DUMP = 1
|
||||
BUILD_CC1101 = 1
|
||||
BUILD_SPEAKER_DEMO = 1
|
||||
endif
|
||||
|
||||
APP_NFC ?= 0
|
||||
@@ -143,7 +144,7 @@ APP_INPUT = 1
|
||||
APP_GUI = 1
|
||||
endif
|
||||
|
||||
APP_IRDA?= 0
|
||||
APP_IRDA ?= 0
|
||||
ifeq ($(APP_IRDA), 1)
|
||||
CFLAGS += -DAPP_IRDA
|
||||
BUILD_IRDA = 1
|
||||
@@ -156,6 +157,19 @@ APP_INPUT = 1
|
||||
APP_GUI = 1
|
||||
endif
|
||||
|
||||
APP_SPEAKER_DEMO ?= 0
|
||||
ifeq ($(APP_SPEAKER_DEMO), 1)
|
||||
CFLAGS += -DAPP_SPEAKER_DEMO
|
||||
BUILD_SPEAKER_DEMO = 1
|
||||
endif
|
||||
BUILD_SPEAKER_DEMO ?= 0
|
||||
ifeq ($(BUILD_SPEAKER_DEMO), 1)
|
||||
CFLAGS += -DBUILD_SPEAKER_DEMO
|
||||
C_SOURCES += $(wildcard $(APP_DIR)/coreglitch_demo_0/*.c)
|
||||
APP_INPUT = 1
|
||||
APP_GUI = 1
|
||||
endif
|
||||
|
||||
# device drivers
|
||||
|
||||
APP_GUI ?= 0
|
||||
|
@@ -232,7 +232,11 @@ extern "C" void cc1101_workaround(void* p) {
|
||||
gui->add_widget(gui, widget, WidgetLayerFullscreen);
|
||||
|
||||
printf("[cc1101] creating device\n");
|
||||
CC1101 cc1101(GpioPin{CC1101_CS_GPIO_Port, CC1101_CS_Pin});
|
||||
GpioPin cs_pin = {CC1101_CS_GPIO_Port, CC1101_CS_Pin};
|
||||
|
||||
// TODO open record
|
||||
GpioPin* cs_pin_record = &cs_pin;
|
||||
CC1101 cc1101(cs_pin_record);
|
||||
printf("[cc1101] init device\n");
|
||||
|
||||
uint8_t address = cc1101.Init();
|
||||
@@ -254,9 +258,11 @@ extern "C" void cc1101_workaround(void* p) {
|
||||
|
||||
// create pin
|
||||
GpioPin led = {GPIOA, GPIO_PIN_8};
|
||||
// TODO open record
|
||||
GpioPin* led_record = &led;
|
||||
|
||||
// configure pin
|
||||
pinMode(led, GpioModeOpenDrain);
|
||||
pinMode(led_record, GpioModeOutputOpenDrain);
|
||||
|
||||
const int16_t RSSI_THRESHOLD = -89;
|
||||
|
||||
@@ -322,7 +328,8 @@ extern "C" void cc1101_workaround(void* p) {
|
||||
}
|
||||
|
||||
digitalWrite(
|
||||
led, (state->last_rssi > RSSI_THRESHOLD && !state->need_cc1101_conf) ? LOW : HIGH);
|
||||
led_record,
|
||||
(state->last_rssi > RSSI_THRESHOLD && !state->need_cc1101_conf) ? LOW : HIGH);
|
||||
|
||||
release_mutex(&state_mutex, state);
|
||||
widget_update(widget);
|
||||
|
@@ -12,13 +12,17 @@
|
||||
/******************************************************************************/
|
||||
GpioPin ss_pin;
|
||||
|
||||
CC1101::CC1101(GpioPin ss_pin) {
|
||||
CC1101::CC1101(GpioPin* ss_pin) {
|
||||
/*
|
||||
pinMode(gdo0_pin, OUTPUT); //GDO0 as asynchronous serial mode input
|
||||
pinMode(gdo2_pin, INPUT); //GDO2 as asynchronous serial mode output
|
||||
*/
|
||||
pinMode(ss_pin, OUTPUT);
|
||||
this->ss_pin = ss_pin;
|
||||
|
||||
// TODO open record
|
||||
this->miso_pin = MISO_PIN;
|
||||
this->miso_pin_record = &this->miso_pin;
|
||||
}
|
||||
//******************************************************************************
|
||||
//SpiInit
|
||||
@@ -108,7 +112,7 @@ byte CC1101::SpiTransfer(byte value) {
|
||||
****************************************************************/
|
||||
void CC1101::SpiWriteReg(byte addr, byte value) {
|
||||
digitalWrite(ss_pin, LOW);
|
||||
while(digitalRead(MISO_PIN))
|
||||
while(digitalRead(this->miso_pin_record))
|
||||
;
|
||||
SpiTransfer(addr);
|
||||
SpiTransfer(value);
|
||||
@@ -126,7 +130,7 @@ void CC1101::SpiWriteBurstReg(byte addr, byte* buffer, byte num) {
|
||||
|
||||
temp = addr | WRITE_BURST;
|
||||
digitalWrite(ss_pin, LOW);
|
||||
while(digitalRead(MISO_PIN))
|
||||
while(digitalRead(this->miso_pin_record))
|
||||
;
|
||||
SpiTransfer(temp);
|
||||
for(i = 0; i < num; i++) {
|
||||
@@ -143,7 +147,7 @@ void CC1101::SpiWriteBurstReg(byte addr, byte* buffer, byte num) {
|
||||
****************************************************************/
|
||||
void CC1101::SpiStrobe(byte strobe) {
|
||||
digitalWrite(ss_pin, LOW);
|
||||
while(digitalRead(MISO_PIN))
|
||||
while(digitalRead(this->miso_pin_record))
|
||||
;
|
||||
SpiTransfer(strobe);
|
||||
digitalWrite(ss_pin, HIGH);
|
||||
@@ -160,7 +164,7 @@ byte CC1101::SpiReadReg(byte addr) {
|
||||
|
||||
temp = addr | READ_SINGLE;
|
||||
digitalWrite(ss_pin, LOW);
|
||||
while(digitalRead(MISO_PIN))
|
||||
while(digitalRead(this->miso_pin_record))
|
||||
;
|
||||
SpiTransfer(temp);
|
||||
value = SpiTransfer(0);
|
||||
@@ -180,7 +184,7 @@ void CC1101::SpiReadBurstReg(byte addr, byte* buffer, byte num) {
|
||||
|
||||
temp = addr | READ_BURST;
|
||||
digitalWrite(ss_pin, LOW);
|
||||
while(digitalRead(MISO_PIN))
|
||||
while(digitalRead(this->miso_pin_record))
|
||||
;
|
||||
SpiTransfer(temp);
|
||||
for(i = 0; i < num; i++) {
|
||||
@@ -200,7 +204,7 @@ byte CC1101::SpiReadStatus(byte addr) {
|
||||
|
||||
temp = addr | READ_BURST;
|
||||
digitalWrite(ss_pin, LOW);
|
||||
while(digitalRead(MISO_PIN))
|
||||
while(digitalRead(this->miso_pin_record))
|
||||
;
|
||||
SpiTransfer(temp);
|
||||
value = SpiTransfer(0);
|
||||
@@ -221,10 +225,10 @@ void CC1101::Reset(void) {
|
||||
digitalWrite(ss_pin, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(ss_pin, LOW);
|
||||
while(digitalRead(MISO_PIN))
|
||||
while(digitalRead(this->miso_pin_record))
|
||||
;
|
||||
SpiTransfer(CC1101_SRES);
|
||||
while(digitalRead(MISO_PIN))
|
||||
while(digitalRead(this->miso_pin_record))
|
||||
;
|
||||
digitalWrite(ss_pin, HIGH);
|
||||
}
|
||||
|
@@ -136,9 +136,11 @@
|
||||
//******************************** class **************************************//
|
||||
class CC1101 {
|
||||
private:
|
||||
GpioPin ss_pin;
|
||||
GpioPin gdo0_pin;
|
||||
GpioPin gdo2_pin;
|
||||
GpioPin* ss_pin;
|
||||
GpioPin miso_pin;
|
||||
GpioPin* miso_pin_record;
|
||||
GpioPin* gdo0_pin;
|
||||
GpioPin* gdo2_pin;
|
||||
|
||||
private:
|
||||
void SpiMode(byte config);
|
||||
@@ -150,7 +152,7 @@ private:
|
||||
void RegConfigSettings(void);
|
||||
|
||||
public:
|
||||
CC1101(GpioPin ss_pin);
|
||||
CC1101(GpioPin* ss_pin);
|
||||
|
||||
void SpiWriteReg(byte addr, byte value);
|
||||
void SpiInit(void);
|
||||
|
@@ -8,15 +8,6 @@ void coreglitch_demo_0(void* p) {
|
||||
|
||||
fuprintf(log, "coreglitch demo!\n");
|
||||
|
||||
// open record
|
||||
FuriRecordSubscriber* fb_record =
|
||||
furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
|
||||
if(fb_record == NULL) {
|
||||
fuprintf(log, "[widget] cannot create fb record\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
float notes[] = {
|
||||
0.0,
|
||||
330.0,
|
||||
@@ -49,25 +40,11 @@ void coreglitch_demo_0(void* p) {
|
||||
}
|
||||
|
||||
// TODO get sound from FURI
|
||||
pwm_set(width, freq, &htim5, TIM_CHANNEL_4);
|
||||
hal_pwm_set(width, freq, &htim5, TIM_CHANNEL_4);
|
||||
// delay(1);
|
||||
|
||||
cnt++;
|
||||
|
||||
u8g2_t* fb = furi_take(fb_record);
|
||||
if(fb != NULL) {
|
||||
u8g2_SetDrawColor(fb, 0);
|
||||
u8g2_DrawBox(fb, 0, 0, 120, 30);
|
||||
|
||||
u8g2_SetFont(fb, u8g2_font_6x10_mf);
|
||||
u8g2_SetDrawColor(fb, 1);
|
||||
u8g2_SetFontMode(fb, 1);
|
||||
char buf[64];
|
||||
sprintf(buf, "freq: %d Hz", (uint32_t)freq);
|
||||
u8g2_DrawStr(fb, 2 + width * 20, 12 + freq / 100, buf);
|
||||
}
|
||||
furi_commit(fb_record);
|
||||
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,20 @@
|
||||
#include "flipper.h"
|
||||
#include "flipper_v2.h"
|
||||
|
||||
void application_blink(void* p) {
|
||||
// create pin
|
||||
GpioPin led = {.pin = GPIO_PIN_8, .port = GPIOA};
|
||||
|
||||
// TODO open record
|
||||
GpioPin* led_record = &led;
|
||||
|
||||
// configure pin
|
||||
pinMode(led, GpioModeOpenDrain);
|
||||
pinMode(led_record, GpioModeOutputOpenDrain);
|
||||
|
||||
while(1) {
|
||||
digitalWrite(led, HIGH);
|
||||
digitalWrite(led_record, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(led, LOW);
|
||||
digitalWrite(led_record, LOW);
|
||||
delay(500);
|
||||
}
|
||||
}
|
@@ -1,11 +1,15 @@
|
||||
#include "flipper.h"
|
||||
#include <string.h>
|
||||
#include "log.h"
|
||||
#include "flipper_v2.h"
|
||||
|
||||
void application_uart_write(void* p) {
|
||||
// Red led for showing progress
|
||||
GpioPin led = {.pin = GPIO_PIN_8, .port = GPIOA};
|
||||
pinMode(led, GpioModeOpenDrain);
|
||||
// TODO open record
|
||||
GpioPin* led_record = &led;
|
||||
|
||||
pinMode(led_record, GpioModeOutputOpenDrain);
|
||||
|
||||
// get_default_log open "tty" record
|
||||
FuriRecordSubscriber* log = get_default_log();
|
||||
@@ -23,9 +27,9 @@ void application_uart_write(void* p) {
|
||||
counter++;
|
||||
|
||||
// flash at every send
|
||||
digitalWrite(led, LOW);
|
||||
digitalWrite(led_record, LOW);
|
||||
delay(50);
|
||||
digitalWrite(led, HIGH);
|
||||
digitalWrite(led_record, HIGH);
|
||||
|
||||
// delay with overall perion of 1s
|
||||
delay(950);
|
||||
|
@@ -56,7 +56,7 @@ void input_task(void* p) {
|
||||
for(;;) {
|
||||
bool changed = false;
|
||||
for(uint32_t i = 0; i < INPUT_COUNT; i++) {
|
||||
bool input_state = app_gpio_read(input_gpio[i]) ^ input_invert[i];
|
||||
bool input_state = gpio_read(&input_gpio[i]) ^ input_invert[i];
|
||||
if(input_state) {
|
||||
if(debounce_counters[i] < DEBOUNCE_TICKS) {
|
||||
debounce_counters[i] += 1;
|
||||
|
@@ -90,13 +90,13 @@ void render_nec(CanvasApi* canvas, State* state) {
|
||||
void input_carrier(Event* event, State* state) {
|
||||
if(event->value.input.input == InputOk) {
|
||||
if(event->value.input.state) {
|
||||
pwm_set(
|
||||
hal_pwm_set(
|
||||
duty_cycles[state->carrier_duty_cycle_id],
|
||||
state->carrier_freq,
|
||||
&htim2,
|
||||
TIM_CHANNEL_4);
|
||||
} else {
|
||||
pwm_stop(&htim2, TIM_CHANNEL_4);
|
||||
hal_pwm_stop(&htim2, TIM_CHANNEL_4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,18 +4,18 @@
|
||||
|
||||
void ir_nec_preambula(void) {
|
||||
// 9ms carrier + 4.5ms pause
|
||||
pwm_set(NEC_DUTY_CYCLE, NEC_CARRIER_FREQUENCY, &htim2, TIM_CHANNEL_4);
|
||||
hal_pwm_set(NEC_DUTY_CYCLE, NEC_CARRIER_FREQUENCY, &htim2, TIM_CHANNEL_4);
|
||||
delay_us(9000);
|
||||
pwm_stop(&htim2, TIM_CHANNEL_4);
|
||||
hal_pwm_stop(&htim2, TIM_CHANNEL_4);
|
||||
delay_us(4500);
|
||||
}
|
||||
|
||||
void ir_nec_send_bit(bool bit) {
|
||||
// 0 is 562.5us carrier + 1687.5us pause
|
||||
// 1 is 562.5us carrier + 562.5us pause
|
||||
pwm_set(NEC_DUTY_CYCLE, NEC_CARRIER_FREQUENCY, &htim2, TIM_CHANNEL_4);
|
||||
hal_pwm_set(NEC_DUTY_CYCLE, NEC_CARRIER_FREQUENCY, &htim2, TIM_CHANNEL_4);
|
||||
delay_us(562.5);
|
||||
pwm_stop(&htim2, TIM_CHANNEL_4);
|
||||
hal_pwm_stop(&htim2, TIM_CHANNEL_4);
|
||||
if(bit) {
|
||||
delay_us(562.5);
|
||||
} else {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include "flipper.h"
|
||||
#include "flipper_v2.h"
|
||||
#include "log.h"
|
||||
|
||||
// #include "flipper-core.h" TODO: Rust build disabled
|
||||
@@ -12,27 +13,31 @@ void flipper_test_app(void* p) {
|
||||
GpioPin green = {.pin = LED_GREEN_Pin, .port = LED_GREEN_GPIO_Port};
|
||||
GpioPin blue = {.pin = LED_BLUE_Pin, .port = LED_BLUE_GPIO_Port};
|
||||
|
||||
// configure pins
|
||||
pinMode(red, GpioModeOpenDrain);
|
||||
pinMode(green, GpioModeOpenDrain);
|
||||
pinMode(blue, GpioModeOpenDrain);
|
||||
GpioPin* red_record = &red;
|
||||
GpioPin* green_record = &green;
|
||||
GpioPin* blue_record = &blue;
|
||||
|
||||
digitalWrite(red, HIGH);
|
||||
digitalWrite(green, HIGH);
|
||||
digitalWrite(blue, LOW);
|
||||
// configure pins
|
||||
pinMode(red_record, GpioModeOutputOpenDrain);
|
||||
pinMode(green_record, GpioModeOutputOpenDrain);
|
||||
pinMode(blue_record, GpioModeOutputOpenDrain);
|
||||
|
||||
digitalWrite(red_record, HIGH);
|
||||
digitalWrite(green_record, HIGH);
|
||||
digitalWrite(blue_record, LOW);
|
||||
|
||||
uint32_t exitcode = run_minunit();
|
||||
|
||||
if(exitcode == 0) {
|
||||
// test passed
|
||||
digitalWrite(red, HIGH);
|
||||
digitalWrite(green, LOW);
|
||||
digitalWrite(blue, HIGH);
|
||||
digitalWrite(red_record, HIGH);
|
||||
digitalWrite(green_record, LOW);
|
||||
digitalWrite(blue_record, HIGH);
|
||||
} else {
|
||||
// test failed
|
||||
digitalWrite(red, LOW);
|
||||
digitalWrite(green, HIGH);
|
||||
digitalWrite(blue, HIGH);
|
||||
digitalWrite(red_record, LOW);
|
||||
digitalWrite(green_record, HIGH);
|
||||
digitalWrite(blue_record, HIGH);
|
||||
}
|
||||
|
||||
set_exitcode(exitcode);
|
||||
|
Reference in New Issue
Block a user