From af5cb9c492d29526cb8aa3ab047fa354fdb972bd Mon Sep 17 00:00:00 2001 From: arturo182 Date: Wed, 27 Jun 2018 20:35:31 +0200 Subject: [PATCH] nrf: Remove unneeded hal files --- ports/nrf/Makefile | 5 -- ports/nrf/hal/hal_gpio.c | 116 ------------------------ ports/nrf/hal/hal_irq.h | 116 ------------------------ ports/nrf/hal/hal_pwm.c | 118 ------------------------- ports/nrf/hal/hal_pwm.h | 100 --------------------- ports/nrf/hal/hal_timer.c | 99 --------------------- ports/nrf/hal/hal_timer.h | 65 -------------- ports/nrf/hal/hal_twi.c | 133 ---------------------------- ports/nrf/hal/hal_twi.h | 105 ---------------------- ports/nrf/hal/hal_uarte.c | 180 -------------------------------------- 10 files changed, 1037 deletions(-) delete mode 100644 ports/nrf/hal/hal_gpio.c delete mode 100644 ports/nrf/hal/hal_irq.h delete mode 100644 ports/nrf/hal/hal_pwm.c delete mode 100644 ports/nrf/hal/hal_pwm.h delete mode 100644 ports/nrf/hal/hal_timer.c delete mode 100644 ports/nrf/hal/hal_timer.h delete mode 100644 ports/nrf/hal/hal_twi.c delete mode 100644 ports/nrf/hal/hal_twi.h delete mode 100644 ports/nrf/hal/hal_uarte.c diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 936cde21bf..d2a29781d7 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -91,13 +91,8 @@ LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc SRC_HAL = $(addprefix hal/,\ hal_uart.c \ - hal_uarte.c \ hal_time.c \ - hal_timer.c \ - hal_twi.c \ - hal_gpio.c \ hal_rng.c \ - hal_pwm.c \ ) SRC_NRFX = $(addprefix nrfx/,\ diff --git a/ports/nrf/hal/hal_gpio.c b/ports/nrf/hal/hal_gpio.c deleted file mode 100644 index af4d4a4074..0000000000 --- a/ports/nrf/hal/hal_gpio.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "hal_gpio.h" -#include "mphalport.h" -#include "hal_irq.h" - -#define GPIOTE_IRQ_NUM GPIOTE_IRQn -#define GPIOTE_BASE ((NRF_GPIOTE_Type *)NRF_GPIOTE_BASE) -#define HAL_GPIOTE_Type NRF_GPIOTE_Type - -static hal_gpio_event_callback_t m_callback; - -void hal_gpio_register_callback(hal_gpio_event_callback_t cb) { - m_callback = cb; - -#if 0 - hal_gpio_event_config_t config; - config.channel = HAL_GPIO_EVENT_CHANNEL_0; - config.event = HAL_GPIO_POLARITY_EVENT_HIGH_TO_LOW; - config.init_level = 1; - config.pin = 13; - config.port = 0; - - // start LFCLK if not already started - if (NRF_CLOCK->LFCLKSTAT == 0) { - NRF_CLOCK->TASKS_LFCLKSTART = 1; - while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0); - NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; - } - - hal_irq_enable(GPIOTE_IRQ_NUM); - hal_irq_priority(GPIOTE_IRQ_NUM, 3); - - hal_gpio_event_config(&config); -#endif -} - -void hal_gpio_event_config(hal_gpio_event_config_t const * p_config) { -#if 0 - hal_gpio_cfg_pin(p_config->port, p_config->pin, HAL_GPIO_MODE_INPUT, HAL_GPIO_PULL_UP); - - uint8_t channel = (uint8_t)p_config->channel; - GPIOTE_BASE->CONFIG[channel] = \ - GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos \ - | p_config->pin << GPIOTE_CONFIG_PSEL_Pos \ - | p_config->event \ - | p_config->init_level << GPIOTE_CONFIG_OUTINIT_Pos; - - GPIOTE_BASE->INTENSET = 1 << channel; - GPIOTE_BASE->EVENTS_IN[channel] = 0; -#endif -} - -#if 0 - -void GPIOTE_IRQHandler(void) { - if (GPIOTE_BASE->EVENTS_IN[0]) { - GPIOTE_BASE->EVENTS_IN[0] = 0; - m_callback(HAL_GPIO_EVENT_CHANNEL_0); - } - if (GPIOTE_BASE->EVENTS_IN[1]) { - GPIOTE_BASE->EVENTS_IN[1] = 0; - m_callback(HAL_GPIO_EVENT_CHANNEL_1); - } - if (GPIOTE_BASE->EVENTS_IN[2]) { - GPIOTE_BASE->EVENTS_IN[2] = 0; - m_callback(HAL_GPIO_EVENT_CHANNEL_2); - } - if (GPIOTE_BASE->EVENTS_IN[3]) { - GPIOTE_BASE->EVENTS_IN[3] = 0; - m_callback(HAL_GPIO_EVENT_CHANNEL_3); - } - - if (GPIOTE_BASE->EVENTS_IN[4]) { - GPIOTE_BASE->EVENTS_IN[4] = 0; - m_callback(HAL_GPIO_EVENT_CHANNEL_4); - } - if (GPIOTE_BASE->EVENTS_IN[5]) { - GPIOTE_BASE->EVENTS_IN[5] = 0; - m_callback(HAL_GPIO_EVENT_CHANNEL_5); - } - if (GPIOTE_BASE->EVENTS_IN[6]) { - GPIOTE_BASE->EVENTS_IN[6] = 0; - m_callback(HAL_GPIO_EVENT_CHANNEL_6); - } - if (GPIOTE_BASE->EVENTS_IN[7]) { - GPIOTE_BASE->EVENTS_IN[7] = 0; - m_callback(HAL_GPIO_EVENT_CHANNEL_7); - } -} - -#endif // if 0 diff --git a/ports/nrf/hal/hal_irq.h b/ports/nrf/hal/hal_irq.h deleted file mode 100644 index a6f0684667..0000000000 --- a/ports/nrf/hal/hal_irq.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef HAL_IRQ_H__ -#define HAL_IRQ_H__ - -#include - -#include "nrf.h" - -#if BLUETOOTH_SD -#include "py/nlr.h" -#include "ble_drv.h" - -#define BLUETOOTH_STACK_ENABLED() (ble_drv_stack_enabled()) - -#define NRF52 -#include "nrf_nvic.h" -#endif // BLUETOOTH_SD - -static inline void hal_irq_clear(uint32_t irq_num) { -#if BLUETOOTH_SD - if (BLUETOOTH_STACK_ENABLED() == 1) { - if (sd_nvic_ClearPendingIRQ(irq_num) != 0) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "IRQ (%d) clear error", irq_num)); - } - } else -#endif // BLUETOOTH_SD - { - NVIC_ClearPendingIRQ(irq_num); - } -} - -static inline void hal_irq_enable(uint32_t irq_num) { - hal_irq_clear(irq_num); - -#if BLUETOOTH_SD - if (BLUETOOTH_STACK_ENABLED() == 1) { - if (sd_nvic_EnableIRQ(irq_num) != 0) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "IRQ (%d) enable error", irq_num)); - } - } else -#endif // BLUETOOTH_SD - { - NVIC_EnableIRQ(irq_num); - } -} - -static inline void hal_irq_disable(uint32_t irq_num) { -#if BLUETOOTH_SD - if (BLUETOOTH_STACK_ENABLED() == 1) { - if (sd_nvic_DisableIRQ(irq_num) != 0) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "IRQ (%d) disable error", irq_num)); - } - } else -#endif // BLUETOOTH_SD - { - NVIC_DisableIRQ(irq_num); - } -} - -static inline void hal_irq_priority(uint32_t irq_num, uint8_t priority) { -#if BLUETOOTH_SD - if (BLUETOOTH_STACK_ENABLED() == 1) { - if (sd_nvic_SetPriority(irq_num, priority) != 0) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "IRQ (%d) priority error", irq_num, priority)); - } - } else -#endif // BLUETOOTH_SD - { - NVIC_SetPriority(irq_num, priority); - } -} - -static inline void hal_irq_pending(uint32_t irq_num) { -#if BLUETOOTH_SD - if (BLUETOOTH_STACK_ENABLED() == 1) { - if (sd_nvic_SetPendingIRQ(irq_num) != 0) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "IRQ (%d) pending error", irq_num)); - } - } else -#endif // BLUETOOTH_SD - { - NVIC_SetPendingIRQ(irq_num); - } -} - -#endif // HAL_IRQ_H__ diff --git a/ports/nrf/hal/hal_pwm.c b/ports/nrf/hal/hal_pwm.c deleted file mode 100644 index c7ae31a996..0000000000 --- a/ports/nrf/hal/hal_pwm.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include - -#include "mphalport.h" -#include "hal_pwm.h" - -#ifdef HAL_PWM_MODULE_ENABLED - -#define PWM_COUNTER_TOP 16000 // 16MHz divided by 16000-> 1ms - -volatile uint16_t g_pwm_seq[4]; -volatile uint16_t g_pwm_period; - -static const uint32_t hal_pwm_frequency_lookup[] = { - PWM_PRESCALER_PRESCALER_DIV_1, // 16MHz - PWM_PRESCALER_PRESCALER_DIV_2, // 8MHz - PWM_PRESCALER_PRESCALER_DIV_4, // 4MHz - PWM_PRESCALER_PRESCALER_DIV_8, // 2MHz - PWM_PRESCALER_PRESCALER_DIV_16, // 1MHz - PWM_PRESCALER_PRESCALER_DIV_32, // 500kHz - PWM_PRESCALER_PRESCALER_DIV_64, // 250kHz - PWM_PRESCALER_PRESCALER_DIV_128 // 125kHz -}; - -void hal_pwm_init(NRF_PWM_Type * p_instance, hal_pwm_init_t const * p_pwm_init) { - g_pwm_period = p_pwm_init->period; - uint16_t pulse_width = ((g_pwm_period * p_pwm_init->duty)/100); - - if (p_pwm_init->pulse_width > 0) { - pulse_width = p_pwm_init->pulse_width; - } - - if (p_pwm_init->mode == HAL_PWM_MODE_HIGH_LOW) { - g_pwm_seq[0] = g_pwm_period - pulse_width; - g_pwm_seq[1] = g_pwm_period - pulse_width; - } else { - g_pwm_seq[0] = pulse_width; - g_pwm_seq[1] = pulse_width; - } - - g_pwm_seq[2] = 0; - g_pwm_seq[3] = 0; - - p_instance->PSEL.OUT[0] = (p_pwm_init->pwm_pin << PWM_PSEL_OUT_PIN_Pos) - | (PWM_PSEL_OUT_CONNECT_Connected << PWM_PSEL_OUT_CONNECT_Pos); - - p_instance->ENABLE = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos); - p_instance->MODE = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos); - p_instance->PRESCALER = (hal_pwm_frequency_lookup[p_pwm_init->freq] << PWM_PRESCALER_PRESCALER_Pos); - p_instance->COUNTERTOP = (p_pwm_init->period << PWM_COUNTERTOP_COUNTERTOP_Pos); - p_instance->LOOP = (PWM_LOOP_CNT_Disabled << PWM_LOOP_CNT_Pos); - p_instance->DECODER = (PWM_DECODER_LOAD_Individual << PWM_DECODER_LOAD_Pos) - | (PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos); - p_instance->SEQ[0].PTR = ((uint32_t)(g_pwm_seq) << PWM_SEQ_PTR_PTR_Pos); - p_instance->SEQ[0].CNT = ((sizeof(g_pwm_seq) / sizeof(uint16_t)) << PWM_SEQ_CNT_CNT_Pos); - - p_instance->SEQ[0].REFRESH = 0; - p_instance->SEQ[0].ENDDELAY = 0; -} - -void hal_pwm_start(NRF_PWM_Type * p_instance) { - p_instance->TASKS_SEQSTART[0] = 1; -} - -void hal_pwm_stop(NRF_PWM_Type * p_instance) { - p_instance->TASKS_SEQSTART[0] = 0; - p_instance->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); -} - -void hal_pwm_freq_set(NRF_PWM_Type * p_instance, uint16_t freq) { -#if 0 - p_instance->PRESCALER = (hal_pwm_frequency_lookup[freq] << PWM_PRESCALER_PRESCALER_Pos); -#endif -} - -void hal_pwm_period_set(NRF_PWM_Type * p_instance, uint16_t period) { -#if 0 - g_pwm_period = period; - p_instance->COUNTERTOP = (g_pwm_period << PWM_COUNTERTOP_COUNTERTOP_Pos); -#endif -} - -void hal_pwm_duty_set(NRF_PWM_Type * p_instance, uint8_t duty) { -#if 0 - uint16_t duty_cycle = ((g_pwm_period * duty)/100); - - g_pwm_seq[0] = duty_cycle; - g_pwm_seq[1] = duty_cycle; -#endif -} - -#endif // HAL_PWM_MODULE_ENABLED diff --git a/ports/nrf/hal/hal_pwm.h b/ports/nrf/hal/hal_pwm.h deleted file mode 100644 index 39590494ad..0000000000 --- a/ports/nrf/hal/hal_pwm.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef HAL_PWM_H__ -#define HAL_PWM_H__ - -#include - -#include "nrf.h" - -#define PWM0 ((NRF_PWM_Type *)NRF_PWM0_BASE) -#define PWM0_IRQ_NUM PWM1_IRQn -#define PWM1 ((NRF_PWM_Type *)NRF_PWM1_BASE) -#define PWM1_IRQ_NUM PWM1_IRQn -#define PWM2 ((NRF_PWM_Type *)NRF_PWM2_BASE) -#define PWM2_IRQ_NUM PWM2_IRQn - -#ifdef NRF52840_XXAA -#define PWM3 ((NRF_PWM_Type *)NRF_PWM3_BASE) -#define PWM3_IRQ_NUM PWM3_IRQn -#endif - -/** - * @brief PWM frequency type definition - */ -typedef enum { - HAL_PWM_FREQ_16Mhz = 0, - HAL_PWM_FREQ_8Mhz, - HAL_PWM_FREQ_4Mhz, - HAL_PWM_FREQ_2Mhz, - HAL_PWM_FREQ_1Mhz, - HAL_PWM_FREQ_500khz, - HAL_PWM_FREQ_250khz, - HAL_PWM_FREQ_125khz -} hal_pwm_freq_t; - -/** - * @brief PWM mode type definition - */ -typedef enum { - HAL_PWM_MODE_LOW_HIGH = 0, - HAL_PWM_MODE_HIGH_LOW -} hal_pwm_mode_t; - - -typedef struct { - uint8_t pwm_pin; - hal_pwm_freq_t freq; - uint8_t duty; - uint16_t pulse_width; - uint16_t period; - hal_pwm_mode_t mode; -} hal_pwm_init_t; - -/** - * @brief PWM handle Structure definition - */ -typedef struct __PWM_HandleTypeDef -{ - NRF_PWM_Type *instance; /* PWM registers base address */ - hal_pwm_init_t init; /* PWM initialization parameters */ -} PWM_HandleTypeDef; - - -void hal_pwm_init(NRF_PWM_Type * p_instance, hal_pwm_init_t const * p_pwm_init); - -void hal_pwm_freq_set(NRF_PWM_Type * p_instance, uint16_t freq); - -void hal_pwm_period_set(NRF_PWM_Type * p_instance, uint16_t period); - -void hal_pwm_duty_set(NRF_PWM_Type * p_instance, uint8_t duty); - -void hal_pwm_start(NRF_PWM_Type * p_instance); - -void hal_pwm_stop(NRF_PWM_Type * p_instance); - -#endif // HAL_PWM_H__ diff --git a/ports/nrf/hal/hal_timer.c b/ports/nrf/hal/hal_timer.c deleted file mode 100644 index cf0883e896..0000000000 --- a/ports/nrf/hal/hal_timer.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "mphalport.h" -#include "hal_timer.h" -#include "hal_irq.h" - -#ifdef HAL_TIMER_MODULE_ENABLED - -static hal_timer_app_callback m_callback; - -void hal_timer_callback_set(hal_timer_app_callback callback) { - m_callback = callback; -} - -void hal_timer_init(hal_timer_conf_t const * p_timer_conf) { - NRF_TIMER_Type * p_timer = TIMER_BASE(p_timer_conf->id); - - p_timer->CC[0] = 1000 * p_timer_conf->period; - p_timer->MODE = TIMER_MODE_MODE_Timer; - p_timer->BITMODE = TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos; - p_timer->PRESCALER = 4; // 1 us - p_timer->INTENSET = TIMER_INTENSET_COMPARE0_Msk; - p_timer->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos); - p_timer->TASKS_CLEAR = 1; - - hal_irq_priority(TIMER_IRQ_NUM(p_timer_conf->id), p_timer_conf->irq_priority); -} - -void hal_timer_start(uint8_t id) { - NRF_TIMER_Type * p_timer = TIMER_BASE(id); - - p_timer->TASKS_CLEAR = 1; - hal_irq_enable(TIMER_IRQ_NUM(id)); - p_timer->TASKS_START = 1; -} - -void hal_timer_stop(uint8_t id) { - NRF_TIMER_Type * p_timer = TIMER_BASE(id); - - hal_irq_disable(TIMER_IRQ_NUM(id)); - p_timer->TASKS_STOP = 1; -} - -static void common_irq_handler(uint8_t id) { - NRF_TIMER_Type * p_timer = TIMER_BASE(id); - - if (p_timer->EVENTS_COMPARE[0]) { - p_timer->EVENTS_COMPARE[0] = 0; - m_callback(id); - } -} - -void TIMER0_IRQHandler(void) { - common_irq_handler(0); -} - -#if (MICROPY_PY_MACHINE_SOFT_PWM != 1) -void TIMER1_IRQHandler(void) { - common_irq_handler(1); -} -#endif - -void TIMER2_IRQHandler(void) { - common_irq_handler(2); -} - -void TIMER3_IRQHandler(void) { - common_irq_handler(3); -} - -void TIMER4_IRQHandler(void) { - common_irq_handler(4); -} - -#endif // HAL_TIMER_MODULE_ENABLED diff --git a/ports/nrf/hal/hal_timer.h b/ports/nrf/hal/hal_timer.h deleted file mode 100644 index 4cdbd61b94..0000000000 --- a/ports/nrf/hal/hal_timer.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef HAL_TIMER_H__ -#define HAL_TIMER_H__ - -#include "nrf.h" - -#define TIMER_BASE_POINTERS (const uint32_t[]){NRF_TIMER0_BASE, \ - NRF_TIMER1_BASE, \ - NRF_TIMER1_BASE, \ - NRF_TIMER1_BASE, \ - NRF_TIMER2_BASE} -#define TIMER_IRQ_VALUES (const uint32_t[]){TIMER0_IRQn, \ - TIMER1_IRQn, \ - TIMER2_IRQn, \ - TIMER3_IRQn, \ - TIMER4_IRQn} - -#define TIMER_BASE(x) ((NRF_TIMER_Type *)TIMER_BASE_POINTERS[x]) -#define TIMER_IRQ_NUM(x) (TIMER_IRQ_VALUES[x]) - -typedef void (*hal_timer_app_callback)(uint8_t id); - -/** - * @brief Timer Configuration Structure definition - */ -typedef struct { - uint8_t id; - uint32_t period; - uint8_t irq_priority; -} hal_timer_conf_t; - -void hal_timer_callback_set(hal_timer_app_callback callback); - -void hal_timer_init(hal_timer_conf_t const * p_timer_config); - -void hal_timer_start(uint8_t id); - -void hal_timer_stop(uint8_t id); - -#endif // HAL_TIMER_H__ diff --git a/ports/nrf/hal/hal_twi.c b/ports/nrf/hal/hal_twi.c deleted file mode 100644 index 65d729c94b..0000000000 --- a/ports/nrf/hal/hal_twi.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "mphalport.h" -#include "hal_twi.h" - -#ifdef HAL_TWI_MODULE_ENABLED - -static const uint32_t hal_twi_frequency_lookup[] = { - TWI_FREQUENCY_FREQUENCY_K100, // 100 kbps - TWI_FREQUENCY_FREQUENCY_K250, // 250 kbps - TWI_FREQUENCY_FREQUENCY_K400, // 400 kbps -}; - -void hal_twi_master_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) { - -#if NRF52840_XXAA - p_instance->PSEL.SCL = p_twi_init->scl_pin->pin; - p_instance->PSEL.SDA = p_twi_init->sda_pin->pin; - p_instance->PSEL.SCL |= (p_twi_init->scl_pin->port << TWI_PSEL_SCL_PORT_Pos); - p_instance->PSEL.SDA |= (p_twi_init->sda_pin->port << TWI_PSEL_SDA_PORT_Pos); -#else - p_instance->PSELSCL = p_twi_init->scl_pin->pin; - p_instance->PSELSDA = p_twi_init->sda_pin->pin; -#endif - - p_instance->FREQUENCY = hal_twi_frequency_lookup[p_twi_init->freq]; - p_instance->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos); -} -#include -void hal_twi_master_tx(NRF_TWI_Type * p_instance, - uint8_t addr, - uint16_t transfer_size, - const uint8_t * tx_data, - bool stop) { - - uint16_t number_of_txd_bytes = 0; - - p_instance->ADDRESS = addr; - - p_instance->EVENTS_TXDSENT = 0; - - p_instance->TXD = tx_data[number_of_txd_bytes]; - p_instance->TASKS_STARTTX = 1; - - while (number_of_txd_bytes < transfer_size) { - // wait for the transaction complete - while (p_instance->EVENTS_TXDSENT == 0) { - ; - } - - number_of_txd_bytes++; - - // TODO: This could go one byte out of bound. - p_instance->TXD = tx_data[number_of_txd_bytes]; - p_instance->EVENTS_TXDSENT = 0; - } - - - if (stop) { - p_instance->EVENTS_STOPPED = 0; - p_instance->TASKS_STOP = 1; - - while (p_instance->EVENTS_STOPPED == 0) { - ; - } - } -} - -void hal_twi_master_rx(NRF_TWI_Type * p_instance, - uint8_t addr, - uint16_t transfer_size, - uint8_t * rx_data, - bool stop) { - - uint16_t number_of_rxd_bytes = 0; - - p_instance->ADDRESS = addr; - - p_instance->EVENTS_RXDREADY = 0; - - p_instance->TASKS_STARTRX = 1; - - while (number_of_rxd_bytes < transfer_size) { - // wait for the transaction complete - while (p_instance->EVENTS_RXDREADY == 0) { - ; - } - - rx_data[number_of_rxd_bytes] = p_instance->RXD; - p_instance->EVENTS_RXDREADY = 0; - - number_of_rxd_bytes++; - } - - if (stop) { - p_instance->EVENTS_STOPPED = 0; - p_instance->TASKS_STOP = 1; - - while (p_instance->EVENTS_STOPPED == 0) { - ; - } - } -} - -void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) { -} - -#endif // HAL_TWI_MODULE_ENABLED - diff --git a/ports/nrf/hal/hal_twi.h b/ports/nrf/hal/hal_twi.h deleted file mode 100644 index 0e8c2a6002..0000000000 --- a/ports/nrf/hal/hal_twi.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef HAL_TWI_H__ -#define HAL_TWI_H__ - -#include -#include "nrf.h" - -#define TWI_BASE_POINTERS (const uint32_t[]){NRF_TWI0_BASE, NRF_TWI1_BASE} -#define TWI_BASE(x) ((NRF_TWI_Type *)TWI_BASE_POINTERS[x]) -#define TWI_IRQ_VALUES (const uint32_t[]){SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, \ - SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn} - -/** - * @brief TWIM Configuration Structure definition - */ -typedef struct { -} hal_twim_init_t; - -/** - * @brief TWIS Configuration Structure definition - */ -typedef struct { -} hal_twis_init_t; - -/** - * @brief TWI clock frequency type definition - */ -typedef enum { - HAL_TWI_FREQ_100_Kbps = 0, - HAL_TWI_FREQ_250_Kbps, - HAL_TWI_FREQ_400_Kbps -} hal_twi_clk_freq_t; - -/** - * @brief TWI role type definition - */ -typedef enum { - HAL_TWI_MASTER, - HAL_TWI_SLAVE -} hal_twi_role_t; - -/** - * @brief TWI Configuration Structure definition - */ -typedef struct { - uint8_t id; /* TWI instance id */ - const pin_obj_t * scl_pin; /* TWI SCL pin */ - const pin_obj_t * sda_pin; /* TWI SDA pin */ - hal_twi_role_t role; /* TWI master/slave */ - hal_twi_clk_freq_t freq; /* TWI frequency */ -} hal_twi_init_t; - -/** - * @brief TWI handle Structure definition - */ -typedef struct __TWI_HandleTypeDef -{ - NRF_TWI_Type *instance; /* TWI register base address */ - hal_twi_init_t init; /* TWI initialization parameters */ -} TWI_HandleTypeDef; - -void hal_twi_master_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init); - -void hal_twi_master_tx(NRF_TWI_Type * p_instance, - uint8_t addr, - uint16_t transfer_size, - const uint8_t * tx_data, - bool stop); - -void hal_twi_master_rx(NRF_TWI_Type * p_instance, - uint8_t addr, - uint16_t transfer_size, - uint8_t * rx_data, - bool stop); - - -void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init); - - -#endif // HAL_TWI_H__ diff --git a/ports/nrf/hal/hal_uarte.c b/ports/nrf/hal/hal_uarte.c deleted file mode 100644 index d3e899b91d..0000000000 --- a/ports/nrf/hal/hal_uarte.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include -#include "mphalport.h" - -#include "hal_uart.h" -#include "hal_irq.h" - -#ifdef HAL_UARTE_MODULE_ENABLED - -#include "nrf.h" - -#ifndef NRF52 -#error "Device not supported." -#endif - -#define UART_BASE(x) ((NRF_UART_Type *)UART_BASE_POINTERS[x]) -#define UART_IRQ_NUM(x) (UART_IRQ_VALUES[x]) - -#define TX_BUF_SIZE 1 -#define RX_BUF_SIZE 1 - -static const uint32_t hal_uart_baudrate_lookup[] = { - UARTE_BAUDRATE_BAUDRATE_Baud1200, ///< 1200 baud. - UARTE_BAUDRATE_BAUDRATE_Baud2400, ///< 2400 baud. - UARTE_BAUDRATE_BAUDRATE_Baud4800, ///< 4800 baud. - UARTE_BAUDRATE_BAUDRATE_Baud9600, ///< 9600 baud. - UARTE_BAUDRATE_BAUDRATE_Baud14400, ///< 14400 baud. - UARTE_BAUDRATE_BAUDRATE_Baud19200, ///< 19200 baud. - UARTE_BAUDRATE_BAUDRATE_Baud28800, ///< 28800 baud. - UARTE_BAUDRATE_BAUDRATE_Baud38400, ///< 38400 baud. - UARTE_BAUDRATE_BAUDRATE_Baud57600, ///< 57600 baud. - UARTE_BAUDRATE_BAUDRATE_Baud76800, ///< 76800 baud. - UARTE_BAUDRATE_BAUDRATE_Baud115200, ///< 115200 baud. - UARTE_BAUDRATE_BAUDRATE_Baud230400, ///< 230400 baud. - UARTE_BAUDRATE_BAUDRATE_Baud250000, ///< 250000 baud. - UARTE_BAUDRATE_BAUDRATE_Baud460800, ///< 460800 baud. - UARTE_BAUDRATE_BAUDRATE_Baud921600, ///< 921600 baud. - UARTE_BAUDRATE_BAUDRATE_Baud1M, ///< 1000000 baud. -}; - -void nrf_sendchar(NRF_UART_Type * p_instance, int ch) { - hal_uart_char_write(p_instance, ch); -} - -void hal_uart_init(NRF_UART_Type * p_instance, hal_uart_init_t const * p_uart_init) { - - NRF_UARTE_Type * uarte_instance = (NRF_UARTE_Type *)p_instance; - - hal_gpio_cfg_pin(p_uart_init->tx_pin->port, p_uart_init->tx_pin->pin, HAL_GPIO_MODE_OUTPUT, HAL_GPIO_PULL_DISABLED); - hal_gpio_pin_set(p_uart_init->tx_pin->port, p_uart_init->tx_pin->pin); - hal_gpio_cfg_pin(p_uart_init->tx_pin->port, p_uart_init->rx_pin->pin, HAL_GPIO_MODE_INPUT, HAL_GPIO_PULL_DISABLED); - - uarte_instance->BAUDRATE = (hal_uart_baudrate_lookup[p_uart_init->baud_rate]); - - uint32_t hwfc = (p_uart_init->flow_control) - ? (UARTE_CONFIG_HWFC_Enabled << UARTE_CONFIG_HWFC_Pos) - : (UARTE_CONFIG_HWFC_Disabled << UARTE_CONFIG_HWFC_Pos); - - uint32_t parity = (p_uart_init->use_parity) - ? (UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos) - : (UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos); - - uarte_instance->CONFIG = (uint32_t)hwfc | (uint32_t)parity; - - uarte_instance->PSEL.RXD = p_uart_init->rx_pin->pin; - uarte_instance->PSEL.TXD = p_uart_init->tx_pin->pin; - -#if NRF52840_XXAA - uarte_instance->PSEL.RXD |= (p_uart_init->rx_pin->port << UARTE_PSEL_RXD_PORT_Pos); - uarte_instance->PSEL.TXD |= (p_uart_init->tx_pin->port << UARTE_PSEL_TXD_PORT_Pos); -#endif - - if (hwfc) { - hal_gpio_cfg_pin(p_uart_init->cts_pin->port, p_uart_init->cts_pin->pin, HAL_GPIO_MODE_INPUT, HAL_GPIO_PULL_DISABLED); - hal_gpio_cfg_pin(p_uart_init->rts_pin->port, p_uart_init->rts_pin->pin, HAL_GPIO_MODE_OUTPUT, HAL_GPIO_PULL_DISABLED); - hal_gpio_pin_set(p_uart_init->rts_pin->port, p_uart_init->rts_pin->pin); - - uarte_instance->PSEL.RTS = p_uart_init->rts_pin->pin; - uarte_instance->PSEL.CTS = p_uart_init->cts_pin->pin; - -#if NRF52840_XXAA - uarte_instance->PSEL.RTS |= (p_uart_init->rx_pin->port << UARTE_PSEL_RTS_PORT_Pos); - uarte_instance->PSEL.CTS |= (p_uart_init->rx_pin->port << UARTE_PSEL_CTS_PORT_Pos); -#endif - } - - hal_irq_priority(p_uart_init->irq_num, p_uart_init->irq_priority); - hal_irq_enable(p_uart_init->irq_num); - - uarte_instance->INTENSET = (UARTE_INTENSET_ENDRX_Set << UARTE_INTENSET_ENDRX_Pos); - uarte_instance->INTENSET = (UARTE_INTENSET_ENDTX_Set << UARTE_INTENSET_ENDTX_Pos); - - uarte_instance->ENABLE = (UARTE_ENABLE_ENABLE_Enabled << UARTE_ENABLE_ENABLE_Pos); - - uarte_instance->EVENTS_ENDTX = 0; - uarte_instance->EVENTS_ENDRX = 0; -} - -hal_uart_error_t hal_uart_char_write(NRF_UART_Type * p_instance, uint8_t ch) { - - NRF_UARTE_Type * uarte_instance = (NRF_UARTE_Type *)p_instance; - - uarte_instance->ERRORSRC = 0; - - - static volatile uint8_t m_tx_buf[TX_BUF_SIZE]; - (void)m_tx_buf; - - uarte_instance->INTENCLR = (UARTE_INTENSET_ENDTX_Set << UARTE_INTENSET_ENDTX_Pos); - - m_tx_buf[0] = ch; - - uarte_instance->TXD.PTR = (uint32_t)((uint8_t *)m_tx_buf); - uarte_instance->TXD.MAXCNT = (uint32_t)sizeof(m_tx_buf); - - uarte_instance->TASKS_STARTTX = 1; - - while((0 == uarte_instance->EVENTS_ENDTX)); - - uarte_instance->EVENTS_ENDTX = 0; - uarte_instance->TASKS_STOPTX = 1; - - uarte_instance->INTENSET = (UARTE_INTENSET_ENDTX_Set << UARTE_INTENSET_ENDTX_Pos); - - return uarte_instance->ERRORSRC; -} - -hal_uart_error_t hal_uart_char_read(NRF_UART_Type * p_instance, uint8_t * ch) { - - NRF_UARTE_Type * uarte_instance = (NRF_UARTE_Type *)p_instance; - - uarte_instance->ERRORSRC = 0; - - static volatile uint8_t m_rx_buf[RX_BUF_SIZE]; - - uarte_instance->INTENCLR = (UARTE_INTENSET_ENDRX_Set << UARTE_INTENSET_ENDRX_Pos); - - uarte_instance->RXD.PTR = (uint32_t)((uint8_t *)m_rx_buf); - uarte_instance->RXD.MAXCNT = (uint32_t)sizeof(m_rx_buf); - - uarte_instance->TASKS_STARTRX = 1; - - while ((0 == uarte_instance->EVENTS_ENDRX)); - - uarte_instance->EVENTS_ENDRX = 0; - uarte_instance->TASKS_STOPRX = 1; - - uarte_instance->INTENSET = (UARTE_INTENSET_ENDRX_Set << UARTE_INTENSET_ENDRX_Pos); - *ch = (uint8_t)m_rx_buf[0]; - - return uarte_instance->ERRORSRC; -} - -#endif // HAL_UARTE_MODULE_ENABLED