summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <thach@tinyusb.org>2017-12-29 21:25:43 +0700
committerhathach <thach@tinyusb.org>2017-12-29 21:25:43 +0700
commita021a9e5f07769ba214b1f5d7223e3010dd8deee (patch)
treefa9f75172ef7a244462dbe5f4b9bb692881dbfec
parent178925640bf645ca44a55118b95ff395f757bdee (diff)
update uart to remove dependency on machine uart module
-rw-r--r--ports/nrf/hal/hal_uart.c10
-rw-r--r--ports/nrf/mphalport.c31
-rw-r--r--ports/nrf/supervisor/serial.c30
3 files changed, 40 insertions, 31 deletions
diff --git a/ports/nrf/hal/hal_uart.c b/ports/nrf/hal/hal_uart.c
index 642ab0d92..1209dc370 100644
--- a/ports/nrf/hal/hal_uart.c
+++ b/ports/nrf/hal/hal_uart.c
@@ -69,16 +69,6 @@ hal_uart_error_t hal_uart_char_write(NRF_UART_Type * p_instance, uint8_t ch) {
}
hal_uart_error_t hal_uart_char_read(NRF_UART_Type * p_instance, uint8_t * ch) {
-// p_instance->ERRORSRC = 0;
-// while (p_instance->EVENTS_RXDRDY != 1) {
-// // Wait for RXD data.
-// }
-//
-// p_instance->EVENTS_RXDRDY = 0;
-// *ch = p_instance->RXD;
-//
-// return p_instance->ERRORSRC;
-
while ( !fifo_read(_ff_uart, ch) ) {
// wait for fifo data
}
diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c
index f6e774827..957d3535d 100644
--- a/ports/nrf/mphalport.c
+++ b/ports/nrf/mphalport.c
@@ -30,8 +30,9 @@
#include "py/mpstate.h"
#include "py/mphal.h"
#include "py/mperrno.h"
-#include "uart.h"
+#include "hal_uart.h"
+#define UART_INSTANCE UART_BASE(0)
FIL* boot_output_file;
// this table converts from HAL_StatusTypeDef to POSIX errno
@@ -46,36 +47,36 @@ NORETURN void mp_hal_raise(HAL_StatusTypeDef status) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(mp_hal_status_to_errno_table[status])));
}
-void mp_hal_set_interrupt_char(int c) {
-
-}
-
#if (MICROPY_PY_BLE_NUS == 0)
int mp_hal_stdin_rx_chr(void) {
for (;;) {
- if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
- return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
+ if ( hal_uart_available(UART_INSTANCE) ) {
+ uint8_t ch;
+ hal_uart_char_read(UART_INSTANCE, &ch);
+ return (int) ch;
}
}
return 0;
}
-bool mp_hal_stdin_any(void)
-{
- return uart_rx_any(MP_STATE_PORT(pyb_stdio_uart));
+bool mp_hal_stdin_any(void) {
+ return hal_uart_available(UART_INSTANCE);
}
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
- if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
- uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
- }
+ while(len--) {
+ hal_uart_char_write(UART_INSTANCE, *str++);
+ }
}
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
- if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
- uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
+ while(len--){
+ if (*str == '\n') {
+ hal_uart_char_write(UART_INSTANCE, '\r');
}
+ hal_uart_char_write(UART_INSTANCE, *str++);
+ }
}
#endif
diff --git a/ports/nrf/supervisor/serial.c b/ports/nrf/supervisor/serial.c
index 0b844fa01..465c8394c 100644
--- a/ports/nrf/supervisor/serial.c
+++ b/ports/nrf/supervisor/serial.c
@@ -29,18 +29,36 @@
#include "py/obj.h"
#include "py/runtime.h"
#include "mphalport.h"
-#include "uart.h"
+#include "pins.h"
+#include "hal_uart.h"
void serial_init(void) {
- uart_init0();
+// uart_init0();
+//
+// mp_obj_t args[2] = {
+// MP_OBJ_NEW_SMALL_INT(0),
+// MP_OBJ_NEW_SMALL_INT(115200),
+// };
+// MP_STATE_PORT(pyb_stdio_uart) = machine_hard_uart_type.make_new((mp_obj_t)&machine_hard_uart_type, MP_ARRAY_SIZE(args), 0, args);
- mp_obj_t args[2] = {
- MP_OBJ_NEW_SMALL_INT(0),
- MP_OBJ_NEW_SMALL_INT(115200),
+ hal_uart_init_t param =
+ {
+ .id = 0,
+ .rx_pin = &MICROPY_HW_UART1_RX,
+ .tx_pin = &MICROPY_HW_UART1_TX,
+ .rts_pin = NULL,
+ .cts_pin = NULL,
+ .flow_control = MICROPY_HW_UART1_HWFC ? true : false,
+ .use_parity = false,
+ .baud_rate = HAL_UART_BAUD_115K2,
+ .irq_priority = 6,
+ .irq_num = UARTE0_UART0_IRQn
};
- MP_STATE_PORT(pyb_stdio_uart) = machine_hard_uart_type.make_new((mp_obj_t)&machine_hard_uart_type, MP_ARRAY_SIZE(args), 0, args);
+
+ hal_uart_init( UART_BASE(0), &param);
}
+
bool serial_connected(void) {
return true;
}