int16_t log_init(void) { uint32_t err_code; UNUSED(err_code); app_uart_comm_params_t params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_ENABLED, false, BAUD_RATE }; if (state != UNINITIALIZED) return -EALREADY; APP_UART_INIT(¶ms, uart_evt_handler, IRQ_PRIORITY_MEDIUM, err_code); state = READY; /* Necessary to fully initialize the UART */ delay(UART_INIT_DELAY); log_newline(); return 0; }
uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) { uint32_t err_code = NRF_SUCCESS; if (events_handler == NULL) { return NRF_ERROR_NULL; } //Check if function was not called before if (m_ser_phy_event_handler != NULL) { return NRF_ERROR_INVALID_STATE; } //Configure UART and register handler //uart_evt_handler is used to handle events produced by low-level uart driver APP_UART_INIT(&comm_params, ser_phy_uart_evt_callback, UART_IRQ_PRIORITY, err_code); //Pull down Rx pin until another side gets up to avoid receiving false bytes due to glitches //on Rx line nrf_gpio_cfg_input(comm_params.rx_pin_no, NRF_GPIO_PIN_PULLDOWN); m_ser_phy_event_handler = events_handler; //If intialization did not go alright return error if (err_code != NRF_SUCCESS) { return NRF_ERROR_INVALID_PARAM; } return err_code; }
uint32_t ser_phy_hci_slip_open(ser_phy_hci_slip_event_handler_t events_handler) { uint32_t err_code; if (events_handler == NULL) { return NRF_ERROR_NULL; } // Check if function was not called before if (m_ser_phy_hci_slip_event_handler != NULL) { return NRF_ERROR_INVALID_STATE; } // Configure UART and register handler // uart_evt_handler is used to handle events produced by low-level uart driver APP_UART_INIT(&comm_params, ser_phy_uart_evt_callback, UART_IRQ_PRIORITY, err_code); mp_small_buffer = m_small_buffer; mp_big_buffer = m_big_buffer; m_ser_phy_hci_slip_event_handler = events_handler; return err_code; }
/** Set up a UART, if pins are -1 they will be guessed */ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { if (device != EV_SERIAL1) return; int baud = getNRFBaud(inf->baudRate); if (baud==0) return jsError("Invalid baud rate %d", inf->baudRate); if (!jshIsPinValid(inf->pinRX) || !jshIsPinValid(inf->pinTX)) return jsError("Invalid RX or TX pins"); uint32_t err_code; const app_uart_comm_params_t comm_params = { pinInfo[inf->pinRX].pin, pinInfo[inf->pinTX].pin, (uint8_t)UART_PIN_DISCONNECTED, (uint8_t)UART_PIN_DISCONNECTED, APP_UART_FLOW_CONTROL_DISABLED, inf->parity!=0, // TODO: ODD or EVEN parity? baud }; APP_UART_INIT(&comm_params, uart0_event_handle, APP_IRQ_PRIORITY_HIGH, err_code); APP_ERROR_CHECK(err_code); }
uint32_t debug_init(void) { uint32_t err_code; nrf_gpio_cfg_output(14); app_uart_comm_params_t params; params.baud_rate = UART_BAUDRATE_BAUDRATE_Baud38400; params.flow_control = APP_UART_FLOW_CONTROL_DISABLED; params.tx_pin_no = 17; params.rx_pin_no = 16; params.use_parity = false; APP_GPIOTE_INIT(1); //app_gpiote_user_enable() APP_UART_INIT(¶ms, uart_evt_handler, APP_IRQ_PRIORITY_HIGH, err_code); return err_code; }