correct pin mapping
This commit is contained in:
5 files changed
+72
-61
No files matched your search
@@ -114,21 +114,17 @@ uint32_t setLoopStacksize(void);
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#ifdef NRF_P1
|
||||
#define digitalPinToPort(P) ( ((P) < 32) ? NRF_P0 : NRF_P1 )
|
||||
#define digitalPinToPort(P) ( (g_ADigitalPinMap[P] < 32) ? NRF_P0 : NRF_P1 )
|
||||
#else
|
||||
#define digitalPinToPort(P) ( NRF_P0 )
|
||||
#endif
|
||||
|
||||
#define digitalPinToBitMask(P) ( 1UL << ( (P) < 32 ? (P) : ((P)-32) ) )
|
||||
#define digitalPinToBitMask(P) ( 1UL << ( g_ADigitalPinMap[P] < 32 ? g_ADigitalPinMap[P] : (g_ADigitalPinMap[P]-32) ) )
|
||||
//#define analogInPinToBit(P) ( )
|
||||
#define portOutputRegister(port) ( &(port->OUT) )
|
||||
#define portInputRegister(port) ( (volatile uint32_t*) &(port->IN) )
|
||||
#define portModeRegister(port) ( &(port->DIR) )
|
||||
|
||||
#define digitalPinHasPWM(P) ( (P) > 1 )
|
||||
|
||||
// PIN_CNF for nrf52
|
||||
#define digitalPinCnfRegister(P) ( &(digitalPinToPort(P)->PIN_CNF[(P) < 32 ? (P): ((P)-32)]) )
|
||||
#define digitalPinHasPWM(P) ( g_ADigitalPinMap[P] > 1 )
|
||||
|
||||
void rtos_idle_callback(void) ATTR_WEAK;
|
||||
/*
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "nrf.h"
|
||||
#include "nrf_soc.h"
|
||||
#include "nrf_sdm.h"
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+8
-2
@@ -120,9 +120,15 @@ void systemOff(uint32_t pin, uint8_t wake_logic)
|
||||
// NRF_POWER->RAM[i].POWERCLR = 0x03UL;
|
||||
// }
|
||||
|
||||
pinMode(pin, wake_logic ? INPUT_PULLDOWN : INPUT_PULLUP);
|
||||
pin = g_ADigitalPinMap[pin];
|
||||
|
||||
*digitalPinCnfRegister(pin) |= ((wake_logic ? GPIO_PIN_CNF_SENSE_High : GPIO_PIN_CNF_SENSE_Low) << GPIO_PIN_CNF_SENSE_Pos);
|
||||
if ( wake_logic )
|
||||
{
|
||||
nrf_gpio_cfg_sense_input(pin, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
|
||||
}else
|
||||
{
|
||||
nrf_gpio_cfg_sense_input(pin, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
|
||||
}
|
||||
|
||||
uint8_t sd_en;
|
||||
(void) sd_softdevice_is_enabled(&sd_en);
|
||||
|
||||
+34
-32
@@ -33,44 +33,46 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
|
||||
|
||||
ulPin = g_ADigitalPinMap[ulPin];
|
||||
|
||||
NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&ulPin);
|
||||
|
||||
// Set pin mode according to chapter '22.6.3 I/O Pin Configuration'
|
||||
switch ( ulMode )
|
||||
{
|
||||
case INPUT:
|
||||
// Set pin to input mode
|
||||
*digitalPinCnfRegister(ulPin) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
break ;
|
||||
port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
break;
|
||||
|
||||
case INPUT_PULLUP:
|
||||
// Set pin to input mode with pull-up resistor enabled
|
||||
*digitalPinCnfRegister(ulPin) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
break ;
|
||||
port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
break;
|
||||
|
||||
case INPUT_PULLDOWN:
|
||||
// Set pin to input mode with pull-down resistor enabled
|
||||
*digitalPinCnfRegister(ulPin) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
break ;
|
||||
port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
break;
|
||||
|
||||
case OUTPUT:
|
||||
// Set pin to output mode
|
||||
*digitalPinCnfRegister(ulPin) = ((uint32_t)GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
break ;
|
||||
port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
break;
|
||||
|
||||
default:
|
||||
// do nothing
|
||||
@@ -85,16 +87,17 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
|
||||
}
|
||||
|
||||
ulPin = g_ADigitalPinMap[ulPin];
|
||||
NRF_GPIO_Type* nrf_port = (NRF_GPIO_Type*) digitalPinToPort(ulPin);
|
||||
|
||||
NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&ulPin);
|
||||
|
||||
switch ( ulVal )
|
||||
{
|
||||
case LOW:
|
||||
nrf_port->OUTCLR = digitalPinToBitMask(ulPin);
|
||||
port->OUTCLR = (1UL << ulPin);
|
||||
break ;
|
||||
|
||||
default:
|
||||
nrf_port->OUTSET = digitalPinToBitMask(ulPin);
|
||||
port->OUTSET = (1UL << ulPin);
|
||||
break ;
|
||||
}
|
||||
}
|
||||
@@ -107,12 +110,11 @@ int digitalRead( uint32_t ulPin )
|
||||
|
||||
ulPin = g_ADigitalPinMap[ulPin];
|
||||
|
||||
NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&ulPin);
|
||||
uint32_t const bm = (1UL << ulPin);
|
||||
|
||||
// Return bit in OUT or IN depending on configured direction
|
||||
NRF_GPIO_Type* nrf_port = (NRF_GPIO_Type*) digitalPinToPort(ulPin);
|
||||
|
||||
if ( ulPin > 32 ) ulPin -= 32;
|
||||
|
||||
return bitRead(nrf_port->DIR, ulPin) ? bitRead(nrf_port->OUT, ulPin) : bitRead(nrf_port->IN, ulPin);
|
||||
return (bm & ((port->DIR & bm) ? port->OUT : port->IN)) ? 1 : 0;
|
||||
}
|
||||
|
||||
void digitalToggle( uint32_t pin )
|
||||
|
||||
@@ -29,6 +29,12 @@ extern "C" {
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
static volatile uint32_t* pincfg_reg(uint32_t pin)
|
||||
{
|
||||
NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&pin);
|
||||
return &port->PIN_CNF[pin];
|
||||
}
|
||||
|
||||
TwoWire::TwoWire(NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn, uint8_t pinSDA, uint8_t pinSCL)
|
||||
{
|
||||
this->_p_twim = p_twim;
|
||||
@@ -43,17 +49,17 @@ void TwoWire::begin(void) {
|
||||
//Master Mode
|
||||
master = true;
|
||||
|
||||
*digitalPinCnfRegister(_uc_pinSCL) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
*pincfg_reg(_uc_pinSCL) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
|
||||
*digitalPinCnfRegister(_uc_pinSDA) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
*pincfg_reg(_uc_pinSDA) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
|
||||
_p_twim->FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K100;
|
||||
_p_twim->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
|
||||
@@ -69,17 +75,17 @@ void TwoWire::begin(uint8_t address) {
|
||||
//Slave mode
|
||||
master = false;
|
||||
|
||||
*digitalPinCnfRegister(_uc_pinSCL) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
*pincfg_reg(_uc_pinSCL) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
|
||||
*digitalPinCnfRegister(_uc_pinSDA) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
*pincfg_reg(_uc_pinSDA) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
|
||||
_p_twis->ADDRESS[0] = address;
|
||||
_p_twis->CONFIG = TWIS_CONFIG_ADDRESS0_Msk;
|
||||
|
||||
Reference in new issue
Block a user