fix multithread logic in template app, update gpio HAL (#250)

* fix multithread logic
* more buffer for dallas id string
* update apps to use new logic
* delay_us small speedup
* add consant qualifier to gpio records and some core api
* fix some apps to use simpler method of getting gpio record
* fix ibutton app, stupid stack problem
This commit is contained in:
DrZlo13
2020-11-19 15:25:32 +03:00
committed by GitHub
parent ccd40497eb
commit a96f23af9b
24 changed files with 137 additions and 88 deletions

View File

@@ -7,11 +7,8 @@ static void event_cb(const void* value, void* ctx) {
const uint32_t BACKLIGHT_TIME = 10000;
void backlight_control(void* p) {
// create pin
GpioPin backlight = backlight_gpio;
// TODO open record
GpioPin* backlight_record = &backlight;
const GpioPin* backlight_record = &backlight_gpio;
// configure pin
gpio_init(backlight_record, GpioModeOutputPushPull);

View File

@@ -1,21 +1,22 @@
#include "flipper_v2.h"
void rgb_set(bool r, bool g, bool b, GpioPin* led_r, GpioPin* led_g, GpioPin* led_b) {
void rgb_set(
bool r,
bool g,
bool b,
const GpioPin* led_r,
const GpioPin* led_g,
const GpioPin* led_b) {
gpio_write(led_r, !r);
gpio_write(led_g, !g);
gpio_write(led_b, !b);
}
void application_blink(void* p) {
// create pin
GpioPin led_r = led_gpio[0];
GpioPin led_g = led_gpio[1];
GpioPin led_b = led_gpio[2];
// TODO open record
GpioPin* led_r_record = &led_r;
GpioPin* led_g_record = &led_g;
GpioPin* led_b_record = &led_b;
const GpioPin* led_r_record = &led_gpio[0];
const GpioPin* led_g_record = &led_gpio[1];
const GpioPin* led_b_record = &led_gpio[2];
// configure pin
gpio_init(led_r_record, GpioModeOutputOpenDrain);

View File

@@ -4,25 +4,21 @@
// start app
void AppiButton::run() {
acquire_state();
mode[0] = new AppiButtonModeDallasRead(this);
mode[1] = new AppiButtonModeDallasEmulate(this);
release_state();
switch_to_mode(0);
// create pin
GpioPin red_led = led_gpio[0];
GpioPin green_led = led_gpio[1];
// TODO open record
red_led_record = &red_led;
green_led_record = &green_led;
red_led_record = &led_gpio[0];
green_led_record = &led_gpio[1];
// configure pin
gpio_init(red_led_record, GpioModeOutputOpenDrain);
gpio_init(green_led_record, GpioModeOutputOpenDrain);
app_ready();
AppiButtonEvent event;
while(1) {
if(get_event(&event, 100)) {
@@ -61,9 +57,7 @@ void AppiButton::render(CanvasApi* canvas) {
canvas->set_font(canvas, FontPrimary);
canvas->draw_str(canvas, 2, 12, "iButton");
if(mode[state.mode_index] != NULL) {
mode[state.mode_index]->render(canvas, &state);
}
mode[state.mode_index]->render(canvas, &state);
}
void AppiButton::blink_red() {

View File

@@ -38,11 +38,11 @@ public:
// with template variables <state, events>
class AppiButton : public AppTemplate<AppiButtonState, AppiButtonEvent> {
public:
GpioPin* red_led_record;
GpioPin* green_led_record;
const GpioPin* red_led_record;
const GpioPin* green_led_record;
static const uint8_t modes_count = 2;
AppTemplateMode<AppiButtonState, AppiButtonEvent>* mode[modes_count] = {NULL, NULL};
AppTemplateMode<AppiButtonState, AppiButtonEvent>* mode[modes_count];
void run();
void render(CanvasApi* canvas);

View File

@@ -17,8 +17,7 @@ public:
app = parent_app;
// TODO open record
GpioPin one_wire_pin = ibutton_gpio;
GpioPin* one_wire_pin_record = &one_wire_pin;
const GpioPin* one_wire_pin_record = &ibutton_gpio;
onewire_slave = new OneWireGpioSlave(one_wire_pin_record);
};
};
@@ -39,9 +38,11 @@ void AppiButtonModeDallasEmulate::render(CanvasApi* canvas, AppiButtonState* sta
canvas->draw_str(canvas, 2, 25, "< dallas emulate");
canvas->draw_str(canvas, 2, 37, "unimplemented");
{
char buf[24];
sprintf(
const uint8_t buffer_size = 32;
char buf[buffer_size];
snprintf(
buf,
buffer_size,
"%x:%x:%x:%x:%x:%x:%x:%x",
state->dallas_address[0],
state->dallas_address[1],

View File

@@ -17,8 +17,7 @@ public:
app = parent_app;
// TODO open record
GpioPin one_wire_pin = ibutton_gpio;
GpioPin* one_wire_pin_record = &one_wire_pin;
const GpioPin* one_wire_pin_record = &ibutton_gpio;
onewire = new OneWireGpio(one_wire_pin_record);
};
@@ -68,9 +67,11 @@ void AppiButtonModeDallasRead::render(CanvasApi* canvas, AppiButtonState* state)
canvas->draw_str(canvas, 2, 25, "dallas read >");
canvas->draw_str(canvas, 2, 37, "touch me, iButton");
{
char buf[24];
sprintf(
const uint8_t buffer_size = 32;
char buf[buffer_size];
snprintf(
buf,
buffer_size,
"%x:%x:%x:%x:%x:%x:%x:%x",
state->dallas_address[0],
state->dallas_address[1],

View File

@@ -5,10 +5,10 @@
class OneWireGpio {
private:
GpioPin* gpio;
const GpioPin* gpio;
public:
OneWireGpio(GpioPin* one_wire_gpio);
OneWireGpio(const GpioPin* one_wire_gpio);
~OneWireGpio();
bool reset(void);
bool read_bit(void);
@@ -20,7 +20,7 @@ public:
void stop(void);
};
OneWireGpio::OneWireGpio(GpioPin* one_wire_gpio) {
OneWireGpio::OneWireGpio(const GpioPin* one_wire_gpio) {
gpio = one_wire_gpio;
}

View File

@@ -5,10 +5,10 @@
class OneWireGpioSlave {
private:
GpioPin* gpio;
const GpioPin* gpio;
public:
OneWireGpioSlave(GpioPin* one_wire_gpio);
OneWireGpioSlave(const GpioPin* one_wire_gpio);
~OneWireGpioSlave();
void start(void);
void stop(void);
@@ -25,7 +25,7 @@ public:
OneWiteTimeType wait_while_gpio(volatile OneWiteTimeType retries, const bool pin_value);
};
OneWireGpioSlave::OneWireGpioSlave(GpioPin* one_wire_gpio) {
OneWireGpioSlave::OneWireGpioSlave(const GpioPin* one_wire_gpio) {
gpio = one_wire_gpio;
}

View File

@@ -264,11 +264,8 @@ void irda(void* p) {
gui->add_widget(gui, widget, GuiLayerFullscreen);
// Red LED
// create pin
GpioPin led = led_gpio[0];
// TODO open record
GpioPin* led_record = &led;
const GpioPin* led_record = &led_gpio[0];
// configure pin
gpio_init(led_record, GpioModeOutputOpenDrain);

View File

@@ -95,6 +95,8 @@ void SdTest::run() {
gpio_init(red_led_record, GpioModeOutputOpenDrain);
gpio_init(green_led_record, GpioModeOutputOpenDrain);
app_ready();
detect_sd_card();
show_warning();
init_sd_card();

View File

@@ -77,6 +77,8 @@ void AppSdNFC::run() {
gpio_init(red_led_record, GpioModeOutputOpenDrain);
gpio_init(green_led_record, GpioModeOutputOpenDrain);
app_ready();
uint8_t rfal_result = rfalNfcInitialize();
if(rfal_result) {
set_text("rfal init fail");