mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-25 20:23:07 +00:00
f5b342abbe
* 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>
49 lines
No EOL
1.4 KiB
C
49 lines
No EOL
1.4 KiB
C
#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;
|
|
} |