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:
49
core/api-hal/api-gpio.c
Normal file
49
core/api-hal/api-gpio.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "api-gpio.h"
|
||||
|
||||
osMutexId_t gpioInitMutex;
|
||||
|
||||
bool gpio_api_init(void) {
|
||||
gpioInitMutex = osMutexNew(NULL);
|
||||
if(gpioInitMutex == NULL) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// init GPIO
|
||||
void gpio_init(GpioPin* gpio, GpioMode mode) {
|
||||
if(osMutexAcquire(gpioInitMutex, osWaitForever) == osOK) {
|
||||
hal_gpio_init(gpio, mode, GpioPullNo, GpioSpeedLow);
|
||||
osMutexRelease(gpioInitMutex);
|
||||
}
|
||||
}
|
||||
|
||||
// init GPIO, extended version
|
||||
void gpio_init_ex(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed) {
|
||||
hal_gpio_init(gpio, mode, pull, speed);
|
||||
}
|
||||
|
||||
// put GPIO to Z-state
|
||||
void gpio_disable(GpioDisableRecord* gpio_record) {
|
||||
GpioPin* gpio_pin = acquire_mutex(gpio_record->gpio_mutex, 0);
|
||||
if(gpio_pin == NULL) {
|
||||
gpio_pin = gpio_record->gpio;
|
||||
}
|
||||
hal_gpio_init(gpio_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
release_mutex(gpio_record->gpio_mutex, gpio_pin);
|
||||
}
|
||||
|
||||
// get GPIO record
|
||||
ValueMutex* gpio_open_mutex(const char* name) {
|
||||
ValueMutex* gpio_mutex = (ValueMutex*)furi_open(name);
|
||||
|
||||
// TODO disable gpio on app exit
|
||||
//if(gpio_mutex != NULL) flapp_on_exit(gpio_disable, gpio_mutex);
|
||||
|
||||
return gpio_mutex;
|
||||
}
|
||||
|
||||
// get GPIO record and acquire mutex
|
||||
GpioPin* gpio_open(const char* name) {
|
||||
ValueMutex* gpio_mutex = gpio_open_mutex(name);
|
||||
GpioPin* gpio_pin = acquire_mutex(gpio_mutex, FLIPPER_HELPER_TIMEOUT);
|
||||
return gpio_pin;
|
||||
}
|
37
core/api-hal/api-gpio.h
Normal file
37
core/api-hal/api-gpio.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include "flipper.h"
|
||||
#include "flipper_v2.h"
|
||||
#include "api-hal-gpio.h"
|
||||
|
||||
typedef struct {
|
||||
ValueMutex* gpio_mutex;
|
||||
GpioPin* gpio;
|
||||
} GpioDisableRecord;
|
||||
|
||||
// init GPIO API
|
||||
bool gpio_api_init();
|
||||
|
||||
// init GPIO
|
||||
void gpio_init(GpioPin* gpio, GpioMode mode);
|
||||
|
||||
// init GPIO, extended version
|
||||
void gpio_init_ex(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed);
|
||||
|
||||
// write value to GPIO, false = LOW, true = HIGH
|
||||
static inline void gpio_write(GpioPin* gpio, bool state) {
|
||||
hal_gpio_write(gpio, state);
|
||||
}
|
||||
|
||||
// read value from GPIO, false = LOW, true = HIGH
|
||||
static inline bool gpio_read(GpioPin* gpio) {
|
||||
return hal_gpio_read(gpio);
|
||||
}
|
||||
|
||||
// put GPIO to Z-state
|
||||
void gpio_disable(GpioDisableRecord* gpio_record);
|
||||
|
||||
// get GPIO record
|
||||
ValueMutex* gpio_open_mutex(const char* name);
|
||||
|
||||
// get GPIO record and acquire mutex
|
||||
GpioPin* gpio_open(const char* name);
|
@@ -2,6 +2,7 @@
|
||||
|
||||
extern "C" {
|
||||
#include "flipper.h"
|
||||
#include "flipper_v2.h"
|
||||
#include "log.h"
|
||||
#include "applications.h"
|
||||
#include "tty_uart.h"
|
||||
@@ -14,6 +15,7 @@ extern "C" void set_exitcode(uint32_t _exitcode) {
|
||||
}
|
||||
|
||||
extern "C" int app() {
|
||||
init_flipper_api();
|
||||
register_tty_uart();
|
||||
|
||||
FuriRecordSubscriber* log = get_default_log();
|
||||
|
@@ -4,4 +4,5 @@ CFLAGS += -I$(CORE_DIR)
|
||||
ASM_SOURCES += $(wildcard $(CORE_DIR)/*.s)
|
||||
C_SOURCES += $(wildcard $(CORE_DIR)/*.c)
|
||||
C_SOURCES += $(wildcard $(CORE_DIR)/api-basic/*.c)
|
||||
C_SOURCES += $(wildcard $(CORE_DIR)/api-hal/*.c)
|
||||
CPP_SOURCES += $(wildcard $(CORE_DIR)/*.cpp)
|
||||
|
@@ -5,7 +5,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
#include "flipper_hal.h"
|
||||
#include "api-hal.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "furi-deprecated.h"
|
||||
|
||||
@@ -17,21 +17,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// Arduino defines
|
||||
|
||||
#define pinMode app_gpio_init
|
||||
#define digitalWrite app_gpio_write
|
||||
#define digitalRead app_gpio_read
|
||||
#define EEMEM
|
||||
#define delayMicroseconds delay_us
|
||||
#define delay osDelay
|
||||
#define byte uint8_t
|
||||
|
||||
#define OUTPUT GpioModeOutput
|
||||
#define INPUT GpioModeInput
|
||||
#define LOW false
|
||||
#define HIGH true
|
||||
#include "flipper_arduino.h"
|
||||
|
||||
void set_exitcode(uint32_t _exitcode);
|
||||
|
||||
|
16
core/flipper_arduino.h
Normal file
16
core/flipper_arduino.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
// Arduino defines
|
||||
#define pinMode gpio_init
|
||||
#define digitalWrite gpio_write
|
||||
#define digitalRead gpio_read
|
||||
#define delayMicroseconds delay_us
|
||||
#define delay osDelay
|
||||
|
||||
#define OUTPUT GpioModeOutputPushPull
|
||||
#define INPUT GpioModeInput
|
||||
#define LOW false
|
||||
#define HIGH true
|
||||
|
||||
typedef uint8_t byte;
|
5
core/flipper_v2.c
Normal file
5
core/flipper_v2.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "flipper_v2.h"
|
||||
|
||||
bool init_flipper_api(void) {
|
||||
return gpio_api_init();
|
||||
}
|
@@ -14,8 +14,15 @@ extern "C" {
|
||||
|
||||
#include "api-basic/memmgr.h"
|
||||
|
||||
#include "api-hal/api-gpio.h"
|
||||
|
||||
#include "gui/gui.h"
|
||||
|
||||
// tmeout for helper functions
|
||||
#define FLIPPER_HELPER_TIMEOUT 10
|
||||
|
||||
bool init_flipper_api(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user