some drying things up (GPIO init in particular)
This commit is contained in:
@@ -271,3 +271,43 @@ void deinit_unit_pins(Unit *unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
error_t configure_gpio_alternate(char port_name, uint8_t pin_num, uint32_t af)
|
||||
{
|
||||
bool suc = true;
|
||||
GPIO_TypeDef *port = port2periph(port_name, &suc);
|
||||
uint32_t ll_pin = pin2ll(pin_num, &suc);
|
||||
if (!suc) return E_BAD_CONFIG;
|
||||
|
||||
if (pin_num < 8)
|
||||
LL_GPIO_SetAFPin_0_7(port, ll_pin, af);
|
||||
else
|
||||
LL_GPIO_SetAFPin_8_15(port, ll_pin, af);
|
||||
|
||||
LL_GPIO_SetPinMode(port, ll_pin, LL_GPIO_MODE_ALTERNATE);
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
error_t configure_sparse_pins(char port_name, uint16_t mask, GPIO_TypeDef **port_dest, uint32_t mode, uint32_t otype)
|
||||
{
|
||||
bool suc = true;
|
||||
GPIO_TypeDef *port = 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);
|
||||
LL_GPIO_SetPinMode(port, ll_pin, mode);
|
||||
LL_GPIO_SetPinOutputType(port, ll_pin, otype);
|
||||
LL_GPIO_SetPinSpeed(port, ll_pin, LL_GPIO_SPEED_FREQ_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
if (port_dest != NULL) {
|
||||
*port_dest = port;
|
||||
}
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -75,4 +75,7 @@ uint16_t port_pack(uint16_t spread, uint16_t mask);
|
||||
*/
|
||||
void deinit_unit_pins(Unit *unit);
|
||||
|
||||
error_t configure_gpio_alternate(char port_name, uint8_t pin_num, uint32_t af);
|
||||
error_t configure_sparse_pins(char port_name, uint16_t mask, GPIO_TypeDef **port_dest, uint32_t mode, uint32_t otype);
|
||||
|
||||
#endif //GEX_PIN_UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user