flipperzero-firmware/firmware/targets/f3/api-hal/api-hal-gpio.h

63 lines
1.8 KiB
C
Raw Normal View History

Firmware, Bootloader: add f3 target. (#215) * Firmware, Bootloader: add f3 target. Refactor code to be portable across targets. * Firmware: remove bkpt * Makefile: debug agent. Debug: f3 platform throw openocd. * freertos-openocd helper * separate hal resources * return of input_dump app * using hew target resources abstration layer for backlight and blink * dirty hack for input driver, f3 has no charging pin * worked input interrupts * working display * F3: switch to 32mHz resonator * F3: configure SD_CS pin * NFC: port to F3. * fat uart app * sd card hal api * separate CC1101 spi config * faster spi gpio for sd card * Assets: disable LFS * Cube: disable css on LSE * Input: format code * Make: add bootloader source code to formatting rule * F3: enable rf by default, adjust clock settings, map all pins where they should be. * libs for coreglitch_demo_0 * nvic priority * bus clocks all to 64 * lf-rfid timer and pin * irda * ir rx setup * tim2 irq handler * Makefile: environment aware mkdir * Makefile, Irukagotchi: commit seq number. * split falling and rising ir rx events * Makefile: proper git branch detect on old git. Firmware: api fix. * fix irda * Makefile,Irukagotchi: date timestamp. * NFC: adjust SPI speed * Irukagotchi: format code * Make: add blackmagic debug in host mode * Makefile: detach blackmagic from terminal signals * Makefile,Irukagotchi: stamp target * add F3 bootloader/firmware to CI Co-authored-by: Aleksandr Kutuzov <aku@plooks.com> Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com> Co-authored-by: aanper <mail@s3f.ru>
2020-11-06 10:52:50 +00:00
#pragma once
#include "main.h"
#include "stdbool.h"
// this defined in xx_hal_gpio.c, so...
#define GPIO_NUMBER (16U)
typedef enum {
GpioModeInput = GPIO_MODE_INPUT,
GpioModeOutputPushPull = GPIO_MODE_OUTPUT_PP,
GpioModeOutputOpenDrain = GPIO_MODE_OUTPUT_OD,
GpioModeAltFunctionPushPull = GPIO_MODE_AF_PP,
GpioModeAltFunctionOpenDrain = GPIO_MODE_AF_OD,
GpioModeAnalog = GPIO_MODE_ANALOG,
GpioModeInterruptRise = GPIO_MODE_IT_RISING,
GpioModeInterruptFall = GPIO_MODE_IT_FALLING,
GpioModeInterruptRiseFall = GPIO_MODE_IT_RISING_FALLING,
GpioModeEventRise = GPIO_MODE_EVT_RISING,
GpioModeEventFall = GPIO_MODE_EVT_FALLING,
GpioModeEventRiseFall = GPIO_MODE_EVT_RISING_FALLING,
} GpioMode;
typedef enum {
GpioSpeedLow = GPIO_SPEED_FREQ_LOW,
GpioSpeedMedium = GPIO_SPEED_FREQ_MEDIUM,
GpioSpeedHigh = GPIO_SPEED_FREQ_HIGH,
GpioSpeedVeryHigh = GPIO_SPEED_FREQ_VERY_HIGH,
} GpioSpeed;
typedef enum {
GpioPullNo = GPIO_NOPULL,
GpioPullUp = GPIO_PULLUP,
GpioPullDown = GPIO_PULLDOWN,
} GpioPull;
typedef struct {
GPIO_TypeDef* port;
uint16_t pin;
} GpioPin;
// init GPIO
void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed);
// write value to GPIO, false = LOW, true = HIGH
static inline void hal_gpio_write(GpioPin* gpio, bool state) {
// writing to BSSR is an atomic operation
if(state == true) {
gpio->port->BSRR = gpio->pin;
} else {
gpio->port->BSRR = (uint32_t)gpio->pin << GPIO_NUMBER;
}
}
// read value from GPIO, false = LOW, true = HIGH
static inline bool hal_gpio_read(const GpioPin* gpio) {
if((gpio->port->IDR & gpio->pin) != 0x00U) {
return true;
} else {
return false;
}
}
bool hal_gpio_read_sd_detect(void);