52#include "nrfx_config.h"
53#include "nrfx_uarte.h"
54#include "hal/nrf_gpio.h"
56static int (*input_handler)(
unsigned char c) = NULL;
58static nrfx_uarte_t instance = NRFX_UARTE_INSTANCE(0);
59static uint8_t uarte_buffer;
60static bool is_initialized;
69 }
while(nrfx_uarte_tx_in_progress(&instance));
70 nrfx_uarte_tx(&instance, &data,
sizeof(data));
80uarte_handler(nrfx_uarte_event_t
const *p_event,
void *p_context)
87 if(p_event->type == NRFX_UARTE_EVT_RX_DONE) {
89 p_data = p_event->data.rxtx.p_data;
90 bytes = p_event->data.rxtx.bytes;
91 for(i = 0; i < bytes; i++) {
92 input_handler(p_data[i]);
94 nrfx_uarte_rx(&instance, &uarte_buffer,
sizeof(uarte_buffer));
102 input_handler = input;
105 nrfx_uarte_rx(&instance, &uarte_buffer,
sizeof(uarte_buffer));
112#if defined(NRF_UARTE0_TX_PORT) && defined(NRF_UARTE0_TX_PIN) \
113 && defined(NRF_UARTE0_RX_PORT) && defined(NRF_UARTE0_RX_PIN)
114 const nrfx_uarte_config_t config = NRFX_UARTE_DEFAULT_CONFIG(
115 NRF_GPIO_PIN_MAP(NRF_UARTE0_TX_PORT, NRF_UARTE0_TX_PIN),
116 NRF_GPIO_PIN_MAP(NRF_UARTE0_RX_PORT, NRF_UARTE0_RX_PIN)
119 nrfx_uarte_init(&instance, &config, uarte_handler);
121 (void) uarte_handler;
125 is_initialized =
true;
void uarte_write(unsigned char data)
Writes to the UARTE driver.
void uarte_init(void)
Initializa the UARTE driver.
void uarte_set_input(int(*input)(unsigned char c))
Sets the input handler called in the event handler.