diff options
author | Maxim Devaev <[email protected]> | 2023-08-25 12:35:28 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-08-25 12:35:28 +0300 |
commit | 21eddbde1c11961d7fb958422d6dd72b94c33375 (patch) | |
tree | 2a869d17932914a4481e6356dc78ab8690cd872c /hid/pico/src/ph_com.c | |
parent | 82ca2b1caed602030d2d849a9e61748ea7249ac9 (diff) |
pico hid bridge mode
Diffstat (limited to 'hid/pico/src/ph_com.c')
-rw-r--r-- | hid/pico/src/ph_com.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/hid/pico/src/ph_com.c b/hid/pico/src/ph_com.c index 697edac9..85a7923a 100644 --- a/hid/pico/src/ph_com.c +++ b/hid/pico/src/ph_com.c @@ -26,6 +26,8 @@ #include "hardware/gpio.h" #include "ph_types.h" +#include "ph_outputs.h" +#include "ph_com_bridge.h" #include "ph_com_spi.h" #include "ph_com_uart.h" @@ -36,32 +38,30 @@ static bool _use_spi = true; +#define _COM(x_func, ...) { \ + if (ph_g_is_bridge) { \ + ph_com_bridge_##x_func(__VA_ARGS__); \ + } else if (_use_spi) { \ + ph_com_spi_##x_func(__VA_ARGS__); \ + } else { \ + ph_com_uart_##x_func(__VA_ARGS__); \ + } \ + } + + void ph_com_init(void (*data_cb)(const u8 *), void (*timeout_cb)(void)) { gpio_init(_USE_SPI_PIN); gpio_set_dir(_USE_SPI_PIN, GPIO_IN); gpio_pull_up(_USE_SPI_PIN); sleep_ms(10); // Нужен небольшой слип для активации pull-up _use_spi = gpio_get(_USE_SPI_PIN); - - if (_use_spi) { - ph_com_spi_init(data_cb, timeout_cb); - } else { - ph_com_uart_init(data_cb, timeout_cb); - } + _COM(init, data_cb, timeout_cb); } void ph_com_task(void) { - if (_use_spi) { - ph_com_spi_task(); - } else { - ph_com_uart_task(); - } + _COM(task); } void ph_com_write(const u8 *data) { - if (_use_spi) { - ph_com_spi_write(data); - } else { - ph_com_uart_write(data); - } + _COM(write, data); } |