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

@@ -1,7 +1,11 @@
#include "api-hal-gpio.h"
// init GPIO
void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed) {
void hal_gpio_init(
const GpioPin* gpio,
const GpioMode mode,
const GpioPull pull,
const GpioSpeed speed) {
// TODO: Alternate Functions
GPIO_InitTypeDef GPIO_InitStruct = {0};

View File

@@ -39,10 +39,14 @@ typedef struct {
} GpioPin;
// init GPIO
void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed);
void hal_gpio_init(
const GpioPin* gpio,
const GpioMode mode,
const GpioPull pull,
const GpioSpeed speed);
// write value to GPIO, false = LOW, true = HIGH
static inline void hal_gpio_write(GpioPin* gpio, bool state) {
static inline void hal_gpio_write(const GpioPin* gpio, const bool state) {
// writing to BSSR is an atomic operation
if(state == true) {
gpio->port->BSRR = gpio->pin;

View File

@@ -2,15 +2,18 @@
#include "assert.h"
#include "cmsis_os2.h"
static uint32_t clk_per_microsecond;
void delay_us_init_DWT(void) {
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
DWT->CYCCNT = 0U;
clk_per_microsecond = SystemCoreClock / 1000000.0f;
}
void delay_us(float microseconds) {
uint32_t start = DWT->CYCCNT;
uint32_t time_ticks = microseconds * (SystemCoreClock / 1000000.0f);
uint32_t time_ticks = microseconds * clk_per_microsecond;
while((DWT->CYCCNT - start) < time_ticks) {
};
}

View File

@@ -2,7 +2,11 @@
#include "api-hal-resources.h"
// init GPIO
void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed) {
void hal_gpio_init(
const GpioPin* gpio,
const GpioMode mode,
const GpioPull pull,
const GpioSpeed speed) {
// TODO: Alternate Functions
GPIO_InitTypeDef GPIO_InitStruct = {0};
@@ -16,10 +20,9 @@ void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed)
bool hal_gpio_read_sd_detect(void) {
bool result = false;
// create pin
GpioPin sd_cs_pin = sd_cs_gpio;
// TODO open record
GpioPin* sd_cs_record = &sd_cs_pin;
const GpioPin* sd_cs_record = &sd_cs_gpio;
// configure pin as input
gpio_init_ex(sd_cs_record, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh);

View File

@@ -39,10 +39,14 @@ typedef struct {
} GpioPin;
// init GPIO
void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed);
void hal_gpio_init(
const GpioPin* gpio,
const GpioMode mode,
const GpioPull pull,
const GpioSpeed speed);
// write value to GPIO, false = LOW, true = HIGH
static inline void hal_gpio_write(GpioPin* gpio, bool state) {
static inline void hal_gpio_write(const GpioPin* gpio, const bool state) {
// writing to BSSR is an atomic operation
if(state == true) {
gpio->port->BSRR = gpio->pin;

View File

@@ -2,7 +2,11 @@
#include <stdio.h>
// init GPIO
void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed){
void hal_gpio_init(
const GpioPin* gpio,
const GpioMode mode,
const GpioPull pull,
const GpioSpeed speed) {
// TODO more mode
if(gpio->pin != 0) {
switch(mode) {
@@ -17,7 +21,7 @@ void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed)
case GpioModeOutputOpenDrain:
printf("[GPIO] %s%d open drain\n", gpio->port, gpio->pin);
break;
default:
printf("[GPIO] %s%d mode %d unsupported\n", gpio->port, gpio->pin, mode);
break;
@@ -28,7 +32,7 @@ void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed)
}
// write value to GPIO, false = LOW, true = HIGH
void hal_gpio_write(GpioPin* gpio, bool state){
void hal_gpio_write(const GpioPin* gpio, const bool state) {
if(gpio->pin != 0) {
if(state) {
printf("[GPIO] %s%d on\n", gpio->port, gpio->pin);
@@ -41,7 +45,7 @@ void hal_gpio_write(GpioPin* gpio, bool state){
}
// read value from GPIO, false = LOW, true = HIGH
bool hal_gpio_read(const GpioPin* gpio){
bool hal_gpio_read(const GpioPin* gpio) {
// TODO emulate pin state?
return false;
}

View File

@@ -40,10 +40,14 @@ typedef struct {
} GpioPin;
// init GPIO
void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed);
void hal_gpio_init(
const GpioPin* gpio,
const GpioMode mode,
const GpioPull pull,
const GpioSpeed speed);
// write value to GPIO, false = LOW, true = HIGH
void hal_gpio_write(GpioPin* gpio, bool state);
void hal_gpio_write(const GpioPin* gpio, const bool state);
// read value from GPIO, false = LOW, true = HIGH
bool hal_gpio_read(const GpioPin* gpio);