Added func for simple periph clock toggling without the horrible if jungle
This commit is contained in:
+4
-25
@@ -6,7 +6,7 @@
|
||||
#include "framework/resources.h"
|
||||
#include "debug_uart.h"
|
||||
#include "plat_compat.h"
|
||||
#include "pin_utils.h"
|
||||
#include "hw_utils.h"
|
||||
|
||||
#if USE_DEBUG_UART
|
||||
|
||||
@@ -56,11 +56,9 @@
|
||||
/** Init the submodule. */
|
||||
void DebugUart_Init(void)
|
||||
{
|
||||
bool suc = true;
|
||||
// Debug UART
|
||||
assert_param(E_SUCCESS == rsc_claim(&UNIT_SYSTEM, DEBUG_USART_RSC));
|
||||
assert_param(E_SUCCESS == rsc_claim(&UNIT_SYSTEM, pin2resource(DEBUG_USART_PORT, DEBUG_USART_PIN, &suc)));
|
||||
assert_param(suc);
|
||||
assert_param(E_SUCCESS == rsc_claim_pin(&UNIT_SYSTEM, DEBUG_USART_PORT, DEBUG_USART_PIN));
|
||||
}
|
||||
|
||||
/** Init the hardware peripheral - this is called early in the boot process */
|
||||
@@ -68,28 +66,10 @@ void DebugUart_PreInit(void)
|
||||
{
|
||||
// configure AF only if platform uses AF numbers
|
||||
#if !PLAT_NO_AFNUM
|
||||
configure_gpio_alternate(DEBUG_USART_PORT, DEBUG_USART_PIN, DEBUG_USART_AF);
|
||||
hw_configure_gpio_af(DEBUG_USART_PORT, DEBUG_USART_PIN, DEBUG_USART_AF);
|
||||
#endif
|
||||
|
||||
if (DEBUG_USART == USART1) {
|
||||
__HAL_RCC_USART1_CLK_ENABLE();
|
||||
}
|
||||
else if (DEBUG_USART == USART2) {
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
}
|
||||
else if (DEBUG_USART == USART3) {
|
||||
__HAL_RCC_USART3_CLK_ENABLE();
|
||||
}
|
||||
#ifdef USART4
|
||||
else if (DEBUG_USART == USART4) {
|
||||
__HAL_RCC_USART4_CLK_ENABLE();
|
||||
}
|
||||
#endif
|
||||
#ifdef USART5
|
||||
else if (DEBUG_USART == USART5) {
|
||||
__HAL_RCC_USART5_CLK_ENABLE();
|
||||
}
|
||||
#endif
|
||||
hw_periph_clock_enable(DEBUG_USART);
|
||||
|
||||
// LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_2, LL_GPIO_MODE_ALTERNATE);
|
||||
// LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_2, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
@@ -118,7 +98,6 @@ void debug_write(const char *buf, uint16_t len)
|
||||
ssize_t _write_r(struct _reent *rptr, int fd, const void *buf, size_t len)
|
||||
{
|
||||
trap("Use of newlib printf");
|
||||
return len;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
#include <utils/avrlibc.h>
|
||||
#include "pin_utils.h"
|
||||
#include "hw_utils.h"
|
||||
#include "macro.h"
|
||||
|
||||
#define PINS_COUNT 16
|
||||
@@ -46,7 +46,7 @@ static GPIO_TypeDef * const port_periphs[] = {
|
||||
COMPILER_ASSERT(PORTS_COUNT == ELEMENTS_IN_ARRAY(port_periphs));
|
||||
|
||||
/** Convert pin number to LL bitfield */
|
||||
uint32_t pin2ll(uint8_t pin_number, bool *suc)
|
||||
uint32_t hw_pin2ll(uint8_t pin_number, bool *suc)
|
||||
{
|
||||
assert_param(suc != NULL);
|
||||
|
||||
@@ -60,7 +60,7 @@ uint32_t pin2ll(uint8_t pin_number, bool *suc)
|
||||
}
|
||||
|
||||
/** Convert port name (A,B,C...) to peripheral struct pointer */
|
||||
GPIO_TypeDef *port2periph(char port_name, bool *suc)
|
||||
GPIO_TypeDef *hw_port2periph(char port_name, bool *suc)
|
||||
{
|
||||
assert_param(suc != NULL);
|
||||
|
||||
@@ -75,7 +75,7 @@ GPIO_TypeDef *port2periph(char port_name, bool *suc)
|
||||
}
|
||||
|
||||
/** Convert a pin to resource handle */
|
||||
Resource pin2resource(char port_name, uint8_t pin_number, bool *suc)
|
||||
Resource hw_pin2resource(char port_name, uint8_t pin_number, bool *suc)
|
||||
{
|
||||
assert_param(suc != NULL);
|
||||
|
||||
@@ -116,7 +116,7 @@ bool parse_pin(const char *value, char *targetName, uint8_t *targetNumber)
|
||||
}
|
||||
|
||||
/** Parse port name */
|
||||
bool parse_port(const char *value, char *targetName)
|
||||
bool parse_port_name(const char *value, char *targetName)
|
||||
{
|
||||
*targetName = (uint8_t) value[0];
|
||||
if (!(*targetName >= 'A' && *targetName < 'A' + PORTS_COUNT)) return false;
|
||||
@@ -177,7 +177,7 @@ uint16_t parse_pinmask(const char *value, bool *suc)
|
||||
}
|
||||
|
||||
/** Convert a pin bitmask to the ASCII format understood by str_parse_pinmask() */
|
||||
char * str_pinmask(uint16_t pins, char *buffer)
|
||||
char * pinmask2str(uint16_t pins, char *buffer)
|
||||
{
|
||||
char *b = buffer;
|
||||
uint32_t start = 0;
|
||||
@@ -230,7 +230,7 @@ char * str_pinmask(uint16_t pins, char *buffer)
|
||||
}
|
||||
|
||||
/** Spread packed port pins using a mask */
|
||||
uint16_t port_spread(uint16_t packed, uint16_t mask)
|
||||
uint16_t pinmask_spread(uint16_t packed, uint16_t mask)
|
||||
{
|
||||
uint16_t result = 0;
|
||||
uint16_t poke = 1;
|
||||
@@ -246,7 +246,7 @@ uint16_t port_spread(uint16_t packed, uint16_t mask)
|
||||
}
|
||||
|
||||
/** Pack spread port pins using a mask */
|
||||
uint16_t port_pack(uint16_t spread, uint16_t mask)
|
||||
uint16_t pinmask_pack(uint16_t spread, uint16_t mask)
|
||||
{
|
||||
uint16_t result = 0;
|
||||
uint16_t poke = 1;
|
||||
@@ -262,7 +262,7 @@ uint16_t port_pack(uint16_t spread, uint16_t mask)
|
||||
}
|
||||
|
||||
/** Configure unit pins as analog (part of unit teardown) */
|
||||
void deinit_unit_pins(Unit *unit)
|
||||
void hw_deinit_unit_pins(Unit *unit)
|
||||
{
|
||||
for (uint32_t rsc = R_PA0; rsc <= R_PF15; rsc++) {
|
||||
if (RSC_IS_HELD(unit->resources, rsc)) {
|
||||
@@ -275,11 +275,15 @@ void deinit_unit_pins(Unit *unit)
|
||||
}
|
||||
|
||||
/** Configure a pin to alternate function */
|
||||
error_t configure_gpio_alternate(char port_name, uint8_t pin_num, uint32_t ll_af)
|
||||
error_t hw_configure_gpio_af(char port_name, uint8_t pin_num, uint32_t ll_af)
|
||||
{
|
||||
#if PLAT_NO_AFNUM
|
||||
trap("Illegal call to hw_configure_gpio_af() on this platform");
|
||||
#else
|
||||
|
||||
bool suc = true;
|
||||
GPIO_TypeDef *port = port2periph(port_name, &suc);
|
||||
uint32_t ll_pin = pin2ll(pin_num, &suc);
|
||||
GPIO_TypeDef *port = hw_port2periph(port_name, &suc);
|
||||
uint32_t ll_pin = hw_pin2ll(pin_num, &suc);
|
||||
if (!suc) return E_BAD_CONFIG;
|
||||
|
||||
if (pin_num < 8)
|
||||
@@ -289,19 +293,21 @@ error_t configure_gpio_alternate(char port_name, uint8_t pin_num, uint32_t ll_af
|
||||
|
||||
LL_GPIO_SetPinMode(port, ll_pin, LL_GPIO_MODE_ALTERNATE);
|
||||
|
||||
#endif
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
/** Configure pins using sparse map */
|
||||
error_t configure_sparse_pins(char port_name, uint16_t mask, GPIO_TypeDef **port_dest, uint32_t ll_mode, uint32_t ll_otype)
|
||||
error_t hw_configure_sparse_pins(char port_name, uint16_t mask, GPIO_TypeDef **port_dest,
|
||||
uint32_t ll_mode, uint32_t ll_otype)
|
||||
{
|
||||
bool suc = true;
|
||||
GPIO_TypeDef *port = port2periph(port_name, &suc);
|
||||
GPIO_TypeDef *port = hw_port2periph(port_name, &suc);
|
||||
if (!suc) return E_BAD_CONFIG;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (mask & (1<<i)) {
|
||||
uint32_t ll_pin = pin2ll((uint8_t) i, &suc);
|
||||
uint32_t ll_pin = hw_pin2ll((uint8_t) i, &suc);
|
||||
LL_GPIO_SetPinMode(port, ll_pin, ll_mode);
|
||||
LL_GPIO_SetPinOutputType(port, ll_pin, ll_otype);
|
||||
LL_GPIO_SetPinSpeed(port, ll_pin, LL_GPIO_SPEED_FREQ_HIGH);
|
||||
@@ -314,3 +320,212 @@ error_t configure_sparse_pins(char port_name, uint16_t mask, GPIO_TypeDef **port
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
void hw_periph_clock_enable(void *periph)
|
||||
{
|
||||
// GPIOs are enabled by default on start-up
|
||||
|
||||
// --- USART ---
|
||||
if (periph == USART1) __HAL_RCC_USART1_CLK_ENABLE();
|
||||
else if (periph == USART2) __HAL_RCC_USART2_CLK_ENABLE();
|
||||
#ifdef USART3
|
||||
else if (periph == USART3) __HAL_RCC_USART3_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef USART4
|
||||
else if (periph == USART4) __HAL_RCC_USART4_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef USART5
|
||||
else if (periph == USART5) __HAL_RCC_USART5_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// --- SPI ---
|
||||
else if (periph == SPI1) __HAL_RCC_SPI1_CLK_ENABLE();
|
||||
#ifdef SPI2
|
||||
else if (periph == SPI2) __HAL_RCC_SPI2_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef SPI3
|
||||
else if (periph == SPI3) __HAL_RCC_SPI3_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// --- I2C ---
|
||||
else if (periph == I2C1) __HAL_RCC_I2C1_CLK_ENABLE();
|
||||
else if (periph == I2C2) __HAL_RCC_I2C2_CLK_ENABLE();
|
||||
#ifdef I2C3
|
||||
else if (periph == I2C3) __HAL_RCC_I2C3_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// --- DMA ---
|
||||
else if (periph == DMA1) __HAL_RCC_DMA1_CLK_ENABLE();
|
||||
#ifdef DMA2
|
||||
else if (periph == DMA2) __HAL_RCC_DMA2_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// --- TIM ---
|
||||
else if (periph == TIM1) __HAL_RCC_TIM1_CLK_ENABLE();
|
||||
else if (periph == TIM2) __HAL_RCC_TIM2_CLK_ENABLE();
|
||||
else if (periph == TIM3) __HAL_RCC_TIM3_CLK_ENABLE();
|
||||
#ifdef TIM4
|
||||
else if (periph == TIM4) __HAL_RCC_TIM4_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM5
|
||||
else if (periph == TIM5) __HAL_RCC_TIM5_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM6
|
||||
else if (periph == TIM6) __HAL_RCC_TIM7_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM7
|
||||
else if (periph == TIM7) __HAL_RCC_TIM7_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM8
|
||||
else if (periph == TIM8) __HAL_RCC_TIM8_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM9
|
||||
else if (periph == TIM9) __HAL_RCC_TIM9_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM11
|
||||
else if (periph == TIM11) __HAL_RCC_TIM11_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM12
|
||||
else if (periph == TIM12) __HAL_RCC_TIM12_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM13
|
||||
else if (periph == TIM13) __HAL_RCC_TIM13_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM14
|
||||
else if (periph == TIM14) __HAL_RCC_TIM14_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM15
|
||||
else if (periph == TIM15) __HAL_RCC_TIM15_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM16
|
||||
else if (periph == TIM16) __HAL_RCC_TIM15_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef TIM17
|
||||
else if (periph == TIM17) __HAL_RCC_TIM17_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// --- ADC ---
|
||||
#ifdef ADC1
|
||||
else if (periph == ADC1) __HAL_RCC_ADC1_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef ADC2
|
||||
else if (periph == ADC2) __HAL_RCC_ADC2_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// --- DAC ---
|
||||
#ifdef DAC1
|
||||
else if (periph == DAC1) __HAL_RCC_DAC1_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef DAC2
|
||||
else if (periph == DAC2) __HAL_RCC_DAC2_CLK_ENABLE();
|
||||
#endif
|
||||
else {
|
||||
dbg("Periph 0x%p missing in hw clock enable func", periph);
|
||||
trap("BUG");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void hw_periph_clock_disable(void *periph)
|
||||
{
|
||||
// GPIOs are enabled by default on start-up
|
||||
|
||||
// --- USART ---
|
||||
if (periph == USART1) __HAL_RCC_USART1_CLK_DISABLE();
|
||||
else if (periph == USART2) __HAL_RCC_USART2_CLK_DISABLE();
|
||||
#ifdef USART3
|
||||
else if (periph == USART3) __HAL_RCC_USART3_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef USART4
|
||||
else if (periph == USART4) __HAL_RCC_USART4_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef USART5
|
||||
else if (periph == USART5) __HAL_RCC_USART5_CLK_DISABLE();
|
||||
#endif
|
||||
|
||||
// --- SPI ---
|
||||
else if (periph == SPI1) __HAL_RCC_SPI1_CLK_DISABLE();
|
||||
#ifdef SPI2
|
||||
else if (periph == SPI2) __HAL_RCC_SPI2_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef SPI3
|
||||
else if (periph == SPI3) __HAL_RCC_SPI3_CLK_DISABLE();
|
||||
#endif
|
||||
|
||||
// --- I2C ---
|
||||
else if (periph == I2C1) __HAL_RCC_I2C1_CLK_DISABLE();
|
||||
else if (periph == I2C2) __HAL_RCC_I2C2_CLK_DISABLE();
|
||||
#ifdef I2C3
|
||||
else if (periph == I2C3) __HAL_RCC_I2C3_CLK_DISABLE();
|
||||
#endif
|
||||
|
||||
// --- DMA ---
|
||||
else if (periph == DMA1) __HAL_RCC_DMA1_CLK_DISABLE();
|
||||
#ifdef DMA2
|
||||
else if (periph == DMA2) __HAL_RCC_DMA2_CLK_DISABLE();
|
||||
#endif
|
||||
|
||||
// --- TIM ---
|
||||
else if (periph == TIM1) __HAL_RCC_TIM1_CLK_DISABLE();
|
||||
else if (periph == TIM2) __HAL_RCC_TIM2_CLK_DISABLE();
|
||||
else if (periph == TIM3) __HAL_RCC_TIM3_CLK_DISABLE();
|
||||
#ifdef TIM4
|
||||
else if (periph == TIM4) __HAL_RCC_TIM4_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM5
|
||||
else if (periph == TIM5) __HAL_RCC_TIM5_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM6
|
||||
else if (periph == TIM6) __HAL_RCC_TIM7_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM7
|
||||
else if (periph == TIM7) __HAL_RCC_TIM7_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM8
|
||||
else if (periph == TIM8) __HAL_RCC_TIM8_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM9
|
||||
else if (periph == TIM9) __HAL_RCC_TIM9_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM11
|
||||
else if (periph == TIM11) __HAL_RCC_TIM11_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM12
|
||||
else if (periph == TIM12) __HAL_RCC_TIM12_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM13
|
||||
else if (periph == TIM13) __HAL_RCC_TIM13_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM14
|
||||
else if (periph == TIM14) __HAL_RCC_TIM14_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM15
|
||||
else if (periph == TIM15) __HAL_RCC_TIM15_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM16
|
||||
else if (periph == TIM16) __HAL_RCC_TIM15_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef TIM17
|
||||
else if (periph == TIM17) __HAL_RCC_TIM17_CLK_DISABLE();
|
||||
#endif
|
||||
|
||||
// --- ADC ---
|
||||
#ifdef ADC1
|
||||
else if (periph == ADC1) __HAL_RCC_ADC1_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef ADC2
|
||||
else if (periph == ADC2) __HAL_RCC_ADC2_CLK_DISABLE();
|
||||
#endif
|
||||
|
||||
// --- DAC ---
|
||||
#ifdef DAC1
|
||||
else if (periph == DAC1) __HAL_RCC_DAC1_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef DAC2
|
||||
else if (periph == DAC2) __HAL_RCC_DAC2_CLK_DISABLE();
|
||||
#endif
|
||||
else {
|
||||
dbg("Periph 0x%p missing in hw clock disable func", periph);
|
||||
trap("BUG");
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* @param suc - set to false on failure, left unchanged on success.
|
||||
* @return LL_GPIO_PIN_x
|
||||
*/
|
||||
uint32_t pin2ll(uint8_t pin_number, bool *suc);
|
||||
uint32_t hw_pin2ll(uint8_t pin_number, bool *suc);
|
||||
|
||||
/**
|
||||
* Convert pin name and number to a resource enum
|
||||
@@ -27,7 +27,7 @@ uint32_t pin2ll(uint8_t pin_number, bool *suc);
|
||||
* @param suc - set to false on failure, left unchanged on success
|
||||
* @return the resource, or R_NONE
|
||||
*/
|
||||
Resource pin2resource(char port_name, uint8_t pin_number, bool *suc);
|
||||
Resource hw_pin2resource(char port_name, uint8_t pin_number, bool *suc);
|
||||
|
||||
/**
|
||||
* Convert port name to peripheral instance
|
||||
@@ -36,7 +36,7 @@ Resource pin2resource(char port_name, uint8_t pin_number, bool *suc);
|
||||
* @param suc - set to false on failure, left unchanged on success.
|
||||
* @return instance
|
||||
*/
|
||||
GPIO_TypeDef *port2periph(char port_name, bool *suc);
|
||||
GPIO_TypeDef *hw_port2periph(char port_name, bool *suc);
|
||||
|
||||
/**
|
||||
* Parse a pin name (e.g. PA0 or A0) to port name and pin number
|
||||
@@ -55,7 +55,7 @@ bool parse_pin(const char *str, char *targetName, uint8_t *targetNumber);
|
||||
* @param targetName - output: port name (one character)
|
||||
* @return success
|
||||
*/
|
||||
bool parse_port(const char *value, char *targetName);
|
||||
bool parse_port_name(const char *value, char *targetName);
|
||||
|
||||
/**
|
||||
* Parse a list of pin numbers with ranges and commands/semicolons to a bitmask.
|
||||
@@ -76,7 +76,7 @@ uint16_t parse_pinmask(const char *value, bool *suc);
|
||||
* @param buffer - output string buffer
|
||||
* @return the output buffer
|
||||
*/
|
||||
char * str_pinmask(uint16_t pins, char *buffer);
|
||||
char * pinmask2str(uint16_t pins, char *buffer);
|
||||
|
||||
/**
|
||||
* Spread packed port pins using a mask
|
||||
@@ -85,7 +85,7 @@ char * str_pinmask(uint16_t pins, char *buffer);
|
||||
* @param mask - positions of the bits (eg. 0x8803)
|
||||
* @return - bits spread to their positions (always counting from right)
|
||||
*/
|
||||
uint16_t port_spread(uint16_t packed, uint16_t mask);
|
||||
uint16_t pinmask_spread(uint16_t packed, uint16_t mask);
|
||||
|
||||
/**
|
||||
* Pack spread port pins using a mask
|
||||
@@ -94,7 +94,7 @@ uint16_t port_spread(uint16_t packed, uint16_t mask);
|
||||
* @param mask - mask of the bits we want to pack (eg. 0x8803)
|
||||
* @return - packed bits, right aligned (eg. 0b1110)
|
||||
*/
|
||||
uint16_t port_pack(uint16_t spread, uint16_t mask);
|
||||
uint16_t pinmask_pack(uint16_t spread, uint16_t mask);
|
||||
|
||||
/**
|
||||
* Set all GPIO resources held by unit to analog.
|
||||
@@ -102,7 +102,7 @@ uint16_t port_pack(uint16_t spread, uint16_t mask);
|
||||
*
|
||||
* @param unit - holding unit
|
||||
*/
|
||||
void deinit_unit_pins(Unit *unit);
|
||||
void hw_deinit_unit_pins(Unit *unit);
|
||||
|
||||
/**
|
||||
* Configure a GPIO pin to alternate function.
|
||||
@@ -112,7 +112,7 @@ void deinit_unit_pins(Unit *unit);
|
||||
* @param ll_af - LL alternate function constant
|
||||
* @return success
|
||||
*/
|
||||
error_t configure_gpio_alternate(char port_name, uint8_t pin_num, uint32_t ll_af);
|
||||
error_t hw_configure_gpio_af(char port_name, uint8_t pin_num, uint32_t ll_af);
|
||||
|
||||
/**
|
||||
* Configure multiple pins using the bitmap pattern
|
||||
@@ -124,7 +124,9 @@ error_t configure_gpio_alternate(char port_name, uint8_t pin_num, uint32_t ll_af
|
||||
* @param ll_otype - LL output type (push/pull, opendrain)
|
||||
* @return success
|
||||
*/
|
||||
error_t configure_sparse_pins(char port_name, uint16_t mask, GPIO_TypeDef **port_dest, uint32_t ll_mode, uint32_t ll_otype);
|
||||
error_t hw_configure_sparse_pins(char port_name,
|
||||
uint16_t mask, GPIO_TypeDef **port_dest,
|
||||
uint32_t ll_mode, uint32_t ll_otype);
|
||||
|
||||
/** Helper struct for defining alternate mappings */
|
||||
struct PinAF {
|
||||
@@ -133,4 +135,16 @@ struct PinAF {
|
||||
uint8_t af;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enable a peripheral clock
|
||||
* @param periph - any peripheral
|
||||
*/
|
||||
void hw_periph_clock_enable(void *periph);
|
||||
|
||||
/**
|
||||
* Disable a peripheral clock
|
||||
* @param periph - any peripheral
|
||||
*/
|
||||
void hw_periph_clock_disable(void *periph);
|
||||
|
||||
#endif //GEX_PIN_UTILS_H
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "framework/settings.h"
|
||||
#include "framework/resources.h"
|
||||
#include "framework/system_settings.h"
|
||||
#include "pin_utils.h"
|
||||
#include "hw_utils.h"
|
||||
#include "lock_jumper.h"
|
||||
#include "status_led.h"
|
||||
|
||||
@@ -27,14 +27,14 @@ void LockJumper_Init(void)
|
||||
bool suc = true;
|
||||
|
||||
// Resolve and claim resource
|
||||
Resource rsc = pin2resource(LOCK_JUMPER_PORT, LOCK_JUMPER_PIN, &suc);
|
||||
Resource rsc = hw_pin2resource(LOCK_JUMPER_PORT, LOCK_JUMPER_PIN, &suc);
|
||||
assert_param(suc);
|
||||
|
||||
assert_param(E_SUCCESS == rsc_claim(&UNIT_SYSTEM, rsc));
|
||||
|
||||
// Resolve pin
|
||||
lock_periph = port2periph(LOCK_JUMPER_PORT, &suc);
|
||||
lock_llpin = pin2ll(LOCK_JUMPER_PIN, &suc);
|
||||
lock_periph = hw_port2periph(LOCK_JUMPER_PORT, &suc);
|
||||
lock_llpin = hw_pin2ll(LOCK_JUMPER_PIN, &suc);
|
||||
assert_param(suc);
|
||||
|
||||
// Configure for input
|
||||
|
||||
+5
-3
@@ -16,6 +16,7 @@
|
||||
#include "units/test/unit_test.h"
|
||||
#include "units/usart/unit_usart.h"
|
||||
#include "units/spi/unit_spi.h"
|
||||
#include "hw_utils.h"
|
||||
|
||||
void plat_init_resources(void)
|
||||
{
|
||||
@@ -25,11 +26,12 @@ void plat_init_resources(void)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
#ifdef GPIOE
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef GPIOF
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
|
||||
hw_periph_clock_enable(DMA1);
|
||||
#ifdef DMA2
|
||||
hw_periph_clock_enable(DMA2);
|
||||
#endif
|
||||
|
||||
// --- Common unit drivers ---
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "platform.h"
|
||||
#include "framework/resources.h"
|
||||
#include "status_led.h"
|
||||
#include "pin_utils.h"
|
||||
#include "hw_utils.h"
|
||||
|
||||
static GPIO_TypeDef *led_periph;
|
||||
static uint32_t led_llpin;
|
||||
@@ -26,8 +26,8 @@ void Indicator_PreInit(void)
|
||||
{
|
||||
bool suc = true;
|
||||
// Resolve pin
|
||||
led_periph = port2periph(STATUS_LED_PORT, &suc);
|
||||
led_llpin = pin2ll(STATUS_LED_PIN, &suc);
|
||||
led_periph = hw_port2periph(STATUS_LED_PORT, &suc);
|
||||
led_llpin = hw_pin2ll(STATUS_LED_PIN, &suc);
|
||||
|
||||
// Configure for output
|
||||
LL_GPIO_SetPinMode(led_periph, led_llpin, LL_GPIO_MODE_OUTPUT);
|
||||
@@ -53,7 +53,7 @@ void Indicator_Init(void)
|
||||
bool suc = true;
|
||||
|
||||
// Resolve and claim resource
|
||||
Resource rsc = pin2resource(STATUS_LED_PORT, STATUS_LED_PIN, &suc);
|
||||
Resource rsc = hw_pin2resource(STATUS_LED_PORT, STATUS_LED_PIN, &suc);
|
||||
assert_param(suc);
|
||||
|
||||
assert_param(E_SUCCESS == rsc_claim(&UNIT_SYSTEM, rsc));
|
||||
|
||||
Reference in New Issue
Block a user