nrf: Remove unused hal files

Makes it easier to keep track of what's left to rewrite.
This commit is contained in:
arturo182 2018-06-26 00:12:58 +02:00
parent c1924f375d
commit 16973d0559
8 changed files with 0 additions and 643 deletions

View File

@ -98,7 +98,6 @@ SRC_HAL = $(addprefix hal/,\
hal_twi.c \
hal_adc.c \
hal_adce.c \
hal_temp.c \
hal_gpio.c \
hal_rng.c \
hal_pwm.c \

View File

@ -1,122 +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_qspie.h"
#ifdef HAL_QSPIE_MODULE_ENABLED
#define QSPI_IRQ_NUM QSPI_IRQn
#define QSPI_BASE ((NRF_QSPI_Type *)NRF_QSPI_BASE)
// frequency, 32 MHz / (SCKFREQ + 1)
static const uint32_t hal_qspi_frequency_lookup[] = {
(15 << QSPI_IFCONFIG1_SCKFREQ_Pos), // 2 Mbps
(7 << QSPI_IFCONFIG1_SCKFREQ_Pos), // 4 Mbps
(3 << QSPI_IFCONFIG1_SCKFREQ_Pos), // 8 Mbps
(1 << QSPI_IFCONFIG1_SCKFREQ_Pos), // 16 Mbps
(0 << QSPI_IFCONFIG1_SCKFREQ_Pos), // 32 Mbps
};
void hal_qspi_master_init(NRF_QSPI_Type * p_instance, hal_qspi_init_t const * p_qspi_init)
{
// configure SCK
p_instance->PSEL.SCK = (p_qspi_init->clk_pin << QSPI_PSEL_SCK_PIN_Pos)
| (p_qspi_init->clk_pin_port << QSPI_PSEL_SCK_PORT_Pos)
| (QSPI_PSEL_SCK_CONNECT_Connected << QSPI_PSEL_SCK_CONNECT_Pos);
// configure CS
if (p_qspi_init->use_csn) {
p_instance->PSEL.CSN = (p_qspi_init->clk_pin << QSPI_PSEL_CSN_PIN_Pos)
| (p_qspi_init->clk_pin_port << QSPI_PSEL_CSN_PORT_Pos)
| (QSPI_PSEL_CSN_CONNECT_Connected << QSPI_PSEL_CSN_CONNECT_Pos);
} else {
p_instance->PSEL.CSN = (QSPI_PSEL_CSN_CONNECT_Disconnected << QSPI_PSEL_CSN_CONNECT_Pos);
}
// configure MOSI/IO0, valid for all configurations
p_instance->PSEL.IO0 = (p_qspi_init->d0_mosi_pin << QSPI_PSEL_IO0_PIN_Pos)
| (p_qspi_init->d0_mosi_pin_port << QSPI_PSEL_IO0_PORT_Pos)
| (QSPI_PSEL_IO0_CONNECT_Connected << QSPI_PSEL_IO0_CONNECT_Pos);
if (p_qspi_init->data_line != HAL_QSPI_DATA_LINE_SINGLE) {
// configure MISO/IO1
p_instance->PSEL.IO1 = (p_qspi_init->d1_miso_pin << QSPI_PSEL_IO1_PIN_Pos)
| (p_qspi_init->d1_miso_pin_port << QSPI_PSEL_IO1_PORT_Pos)
| (QSPI_PSEL_IO1_CONNECT_Connected << QSPI_PSEL_IO1_CONNECT_Pos);
if (p_qspi_init->data_line == HAL_QSPI_DATA_LINE_QUAD) {
// configure IO2
p_instance->PSEL.IO2 = (p_qspi_init->d2_pin << QSPI_PSEL_IO2_PIN_Pos)
| (p_qspi_init->d2_pin_port << QSPI_PSEL_IO2_PORT_Pos)
| (QSPI_PSEL_IO2_CONNECT_Connected << QSPI_PSEL_IO2_CONNECT_Pos);
// configure IO3
p_instance->PSEL.IO3 = (p_qspi_init->d3_pin << QSPI_PSEL_IO3_PIN_Pos)
| (p_qspi_init->d3_pin_port << QSPI_PSEL_IO3_PORT_Pos)
| (QSPI_PSEL_IO3_CONNECT_Connected << QSPI_PSEL_IO3_CONNECT_Pos);
}
}
uint32_t mode;
switch (p_qspi_init->mode) {
case HAL_SPI_MODE_CPOL0_CPHA0:
mode = (QSPI_IFCONFIG1_SPIMODE_MODE0 << QSPI_IFCONFIG1_SPIMODE_Pos);
break;
case HAL_SPI_MODE_CPOL1_CPHA1:
mode = (QSPI_IFCONFIG1_SPIMODE_MODE3 << QSPI_IFCONFIG1_SPIMODE_Pos);
break;
default:
mode = 0;
break;
}
// interface config1
p_instance->IFCONFIG1 = hal_qspi_frequency_lookup[p_qspi_init->freq]
| mode
| (1 << QSPI_IFCONFIG1_SCKDELAY_Pos); // number of 16 MHz periods (62.5 ns)
p_instance->ENABLE = 1;
}
void hal_qspi_master_tx_rx(NRF_QSPI_Type * p_instance,
uint16_t transfer_size,
const uint8_t * tx_data,
uint8_t * rx_data)
{
p_instance->READ.DST = (uint32_t)rx_data;
p_instance->READ.CNT = transfer_size;
p_instance->READ.SRC = (uint32_t)tx_data;
p_instance->READ.CNT = transfer_size;
p_instance->TASKS_ACTIVATE = 1;
while (p_instance->EVENTS_READY == 0) {
;
}
p_instance->TASKS_ACTIVATE = 0;
}
#endif // HAL_QSPIE_MODULE_ENABLED

View File

@ -1,110 +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_QSPIE_H__
#define HAL_QSPIE_H__
#ifdef HAL_QSPIE_MODULE_ENABLED
#if NRF52840_XXAA
#include <nrf.h>
#else
#error "Device not supported."
#endif
/**
* @brief Quad SPI clock frequency type definition
*/
typedef enum {
HAL_FREQ_2_Mbps,
HAL_FREQ_4_Mbps,
HAL_FREQ_8_Mbps,
HAL_FREQ_16_Mbps,
HAL_FREQ_32_Mbps
} hal_qspi_clk_freq_t;
/**
* @brief Quad SPI mode type definition
*/
typedef enum {
HAL_SPI_MODE_CPOL0_CPHA0 = 0, // CPOL = 0, CPHA = 0 (data on leading edge)
HAL_SPI_MODE_CPOL1_CPHA1 = 3 // CPOL = 1, CPHA = 1 (data on trailing edge)
} hal_qspi_mode_t;
/**
* @brief Quad SPI data line configuration type definition
*/
typedef enum {
HAL_QSPI_DATA_LINE_SINGLE,
HAL_QSPI_DATA_LINE_DUAL,
HAL_QSPI_DATA_LINE_QUAD
} hal_qspi_data_line_t;
/**
* @brief Quad SPI Configuration Structure definition
*/
typedef struct {
uint8_t d0_mosi_pin;
uint8_t d1_miso_pin;
uint8_t d2_pin;
uint8_t d3_pin;
uint8_t clk_pin;
uint8_t csn_pin;
uint8_t d0_mosi_pin_port;
uint8_t d1_miso_pin_port;
uint8_t d2_pin_port;
uint8_t d3_pin_port;
uint8_t clk_pin_port;
uint8_t csn_pin_port;
bool use_csn;
hal_qspi_mode_t mode;
hal_qspi_data_line_t data_line;
hal_qspi_clk_freq_t freq;
} hal_qspi_init_t;
/**
* @brief Quad SPI handle Structure definition
*/
typedef struct __QSPI_HandleTypeDef
{
NRF_QSPI_Type *instance; /* QSPI registers base address */
hal_qspi_init_t init; /* QSPI initialization parameters */
} QSPI_HandleTypeDef;
void hal_qspi_master_init(NRF_QSPI_Type * p_instance, hal_qspi_init_t const * p_qspi_init);
void hal_qspi_master_tx_rx(NRF_QSPI_Type * p_instance,
uint16_t transfer_size,
const uint8_t * tx_data,
uint8_t * rx_data);
#endif // HAL_QSPIE_MODULE_ENABLED
#endif // HAL_QSPIE_H__

View File

@ -1,119 +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_rtc.h"
#include "hal_irq.h"
#ifdef HAL_RTC_MODULE_ENABLED
#define HAL_LFCLK_FREQ (32768UL)
#define HAL_RTC_FREQ (10UL)
#define HAL_RTC_COUNTER_PRESCALER ((HAL_LFCLK_FREQ/HAL_RTC_FREQ)-1)
static hal_rtc_app_callback m_callback;
static uint32_t m_period[sizeof(RTC_BASE_POINTERS) / sizeof(uint32_t)];
void hal_rtc_callback_set(hal_rtc_app_callback callback) {
m_callback = callback;
}
void hal_rtc_init(hal_rtc_conf_t const * p_rtc_conf) {
NRF_RTC_Type * p_rtc = RTC_BASE(p_rtc_conf->id);
// 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;
}
m_period[p_rtc_conf->id] = p_rtc_conf->period;
p_rtc->PRESCALER = HAL_RTC_COUNTER_PRESCALER;
hal_irq_priority(RTC_IRQ_NUM(p_rtc_conf->id), p_rtc_conf->irq_priority);
}
void hal_rtc_start(uint8_t id) {
NRF_RTC_Type * p_rtc = RTC_BASE(id);
uint32_t period = HAL_RTC_FREQ * m_period[id];
uint32_t counter = p_rtc->COUNTER;
p_rtc->CC[0] = counter + period;
p_rtc->EVTENSET = RTC_EVTEN_COMPARE0_Msk;
p_rtc->INTENSET = RTC_INTENSET_COMPARE0_Msk;
hal_irq_clear(RTC_IRQ_NUM(id));
hal_irq_enable(RTC_IRQ_NUM(id));
p_rtc->TASKS_START = 1;
}
void hal_rtc_stop(uint8_t id) {
NRF_RTC_Type * p_rtc = RTC_BASE(id);
p_rtc->EVTENCLR = RTC_EVTEN_COMPARE0_Msk;
p_rtc->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
hal_irq_disable(RTC_IRQ_NUM(id));
p_rtc->TASKS_STOP = 1;
}
static void common_irq_handler(uint8_t id) {
NRF_RTC_Type * p_rtc = RTC_BASE(id);
// clear all events
p_rtc->EVENTS_COMPARE[0] = 0;
p_rtc->EVENTS_COMPARE[1] = 0;
p_rtc->EVENTS_COMPARE[2] = 0;
p_rtc->EVENTS_COMPARE[3] = 0;
p_rtc->EVENTS_TICK = 0;
p_rtc->EVENTS_OVRFLW = 0;
m_callback(id);
}
void RTC0_IRQHandler(void)
{
common_irq_handler(0);
}
void RTC1_IRQHandler(void)
{
common_irq_handler(1);
}
void RTC2_IRQHandler(void)
{
common_irq_handler(2);
}
#endif // HAL_RTC_MODULE_ENABLED

View File

@ -1,61 +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_RTC_H__
#define HAL_RTC_H__
#include "nrf.h"
#define RTC_BASE_POINTERS (const uint32_t[]){NRF_RTC0_BASE, \
NRF_RTC1_BASE, \
NRF_RTC2_BASE}
#define RTC_IRQ_VALUES (const uint32_t[]){RTC0_IRQn, \
RTC1_IRQn, \
RTC2_IRQn}
#define RTC_BASE(x) ((NRF_RTC_Type *)RTC_BASE_POINTERS[x])
#define RTC_IRQ_NUM(x) (RTC_IRQ_VALUES[x])
typedef void (*hal_rtc_app_callback)(uint8_t id);
/**
* @brief RTC Configuration Structure definition
*/
typedef struct {
uint8_t id; /* RTC instance id */
uint32_t period; /* RTC period in ms */
uint32_t irq_priority; /* RTC IRQ priority */
} hal_rtc_conf_t;
void hal_rtc_callback_set(hal_rtc_app_callback callback);
void hal_rtc_init(hal_rtc_conf_t const * p_rtc_config);
void hal_rtc_start(uint8_t id);
void hal_rtc_stop(uint8_t id);
#endif // HAL_RTC_H__

View File

@ -1,76 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Bander F. Ajba
*
* 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 <stdio.h>
#include <stdint.h>
#include "mphalport.h"
#include "hal_temp.h"
#if BLUETOOTH_SD
#include "py/nlr.h"
#include "ble_drv.h"
#include "nrf_soc.h"
#define BLUETOOTH_STACK_ENABLED() (ble_drv_stack_enabled())
#endif // BLUETOOTH_SD
#ifdef HAL_TEMP_MODULE_ENABLED
void hal_temp_init(void) {
// @note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module
*(uint32_t *) 0x4000C504 = 0;
}
int32_t hal_temp_read(void) {
#if BLUETOOTH_SD
if (BLUETOOTH_STACK_ENABLED() == 1) {
int32_t temp;
(void)sd_temp_get(&temp);
return temp / 4; // resolution of 0.25 degree celsius
}
#endif // BLUETOOTH_SD
int32_t volatile temp;
hal_temp_init();
NRF_TEMP->TASKS_START = 1; // Start the temperature measurement.
while (NRF_TEMP->EVENTS_DATARDY == 0) {
// Do nothing.
}
NRF_TEMP->EVENTS_DATARDY = 0;
// @note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register.
temp = (((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP) / 4);
// @note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs.
NRF_TEMP->TASKS_STOP = 1; // Stop the temperature measurement.
return temp;
}
#endif // HAL_TEMP_MODULE_ENABLED

View File

@ -1,39 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Bander F. Ajba
*
* 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_TEMP_H__
#define HAL_TEMP_H__
#include "nrf.h"
#define MASK_SIGN (0x00000200UL)
#define MASK_SIGN_EXTENSION (0xFFFFFC00UL)
void hal_temp_init(void);
int32_t hal_temp_read(void);
#endif

View File

@ -1,115 +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_TWIE_MODULE_ENABLED
// EasyDMA variants
#define TWI_MASTER_BASE(x) ((NRF_TWIM_Type *)TWI_BASE_POINTERS[x])
#define TWI_SLAVE_BASE(x) ((NRF_TWIS_Type *)TWI_BASE_POINTERS[x])
static const uint32_t hal_twi_frequency_lookup[] = {
TWIM_FREQUENCY_FREQUENCY_K100, // 100 kbps
TWIM_FREQUENCY_FREQUENCY_K250, // 250 kbps
TWIM_FREQUENCY_FREQUENCY_K400, // 400 kbps
};
void hal_twi_master_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {
// cast to master type
NRF_TWIM_Type * twim_instance = (NRF_TWIM_Type *)p_instance;
twim_instance->PSEL.SCL = p_twi_init->scl_pin->pin;
twim_instance->PSEL.SDA = p_twi_init->sda_pin->pin;
#if NRF52840_XXAA
twim_instance->PSEL.SCL |= (p_twi_init->scl_pin->port << TWIM_PSEL_SCL_PORT_Pos);
twim_instance->PSEL.SDA |= (p_twi_init->sda_pin->port << TWIM_PSEL_SDA_PORT_Pos);
#endif
twim_instance->FREQUENCY = hal_twi_frequency_lookup[p_twi_init->freq];
twim_instance->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
}
#include <stdio.h>
void hal_twi_master_tx(NRF_TWI_Type * p_instance,
uint8_t addr,
uint16_t transfer_size,
const uint8_t * tx_data,
bool stop) {
// cast to master type
NRF_TWIM_Type * twim_instance = (NRF_TWIM_Type *)p_instance;
twim_instance->ADDRESS = addr;
printf("Hal I2C transfer size: %u, addr: %x, stop: %u\n", transfer_size, addr, stop);
twim_instance->TXD.MAXCNT = transfer_size;
twim_instance->TXD.PTR = (uint32_t)tx_data;
if (stop) {
twim_instance->SHORTS = TWIM_SHORTS_LASTTX_STOP_Msk;
} else {
twim_instance->SHORTS = TWIM_SHORTS_LASTTX_SUSPEND_Msk;
}
if (twim_instance->EVENTS_SUSPENDED == 1) {
printf("Resuming\n");
twim_instance->EVENTS_SUSPENDED = 0;
twim_instance->EVENTS_STOPPED = 0;
twim_instance->TASKS_RESUME = 1; // in case of resume
} else {
printf("Starting\n");
twim_instance->EVENTS_SUSPENDED = 0;
twim_instance->EVENTS_STOPPED = 0;
twim_instance->TASKS_STARTTX = 1;
}
printf("Going into loop\n");
while (twim_instance->EVENTS_STOPPED == 0 && twim_instance->EVENTS_SUSPENDED == 0) {
;
}
}
void hal_twi_master_rx(NRF_TWI_Type * p_instance,
uint8_t addr,
uint16_t transfer_size,
const uint8_t * rx_data) {
// cast to master type
NRF_TWIM_Type * twim_instance = (NRF_TWIM_Type *)p_instance;
twim_instance->ADDRESS = addr;
}
void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {
// cast to slave type
NRF_TWIS_Type * twis_instance = (NRF_TWIS_Type *)p_instance;
(void)twis_instance;
}
#endif // HAL_TWIE_MODULE_ENABLED