adding nrf52840 port1 (pin > 32) support
- also remove ledToggle()
This commit is contained in:
1 parent
3ab35ab121
commit
bba2a74b23
10 files changed
+71
-77
No files matched your search
@@ -119,13 +119,17 @@ uint32_t setLoopStacksize(void);
|
||||
#define digitalPinToPort(P) ( NRF_P0 )
|
||||
#endif
|
||||
|
||||
#define digitalPinToBitMask(P) ( 1 << (P) )
|
||||
#define digitalPinToBitMask(P) ( 1UL << ( (P) < 32 ? (P) : ((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)]) )
|
||||
|
||||
void rtos_idle_callback(void) ATTR_WEAK;
|
||||
/*
|
||||
* digitalPinToTimer(..) is AVR-specific and is not defined for nRF52
|
||||
|
||||
+2
-2
@@ -33,14 +33,14 @@ uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
|
||||
// pulse width measuring loop and achieve finer resolution. calling
|
||||
// digitalRead() instead yields much coarser resolution.
|
||||
// PinDescription p = g_APinDescription[pin];
|
||||
uint32_t bit = 1 << pin; //p.ulPin;
|
||||
uint32_t bit = digitalPinToBitMask(pin); //p.ulPin;
|
||||
uint32_t stateMask = state ? bit : 0;
|
||||
|
||||
// convert the timeout from microseconds to a number of times through
|
||||
// the initial loop; it takes (roughly) 13 clock cycles per iteration.
|
||||
uint32_t maxloops = microsecondsToClockCycles(timeout) / 13;
|
||||
|
||||
uint32_t width = countPulseASM(&(NRF_GPIO->IN), bit, stateMask, maxloops);
|
||||
uint32_t width = countPulseASM(portInputRegister(digitalPinToPort(pin)), bit, stateMask, maxloops);
|
||||
|
||||
// convert the reading to microseconds. The loop has been determined
|
||||
// to be 13 clock cycles long and have about 16 clocks between the edge
|
||||
|
||||
+6
-10
@@ -61,7 +61,10 @@ void init( void )
|
||||
NRF_RTC1->TASKS_CLEAR = 1;
|
||||
|
||||
// Make sure all pin is set HIGH when pinmode() is called
|
||||
NRF_GPIO->OUTSET = UINT32_MAX;
|
||||
NRF_P0->OUTSET = UINT32_MAX;
|
||||
#ifdef NRF_P1
|
||||
NRF_P1->OUTSET = UINT32_MAX;
|
||||
#endif
|
||||
}
|
||||
|
||||
void enterUf2Dfu(void)
|
||||
@@ -117,16 +120,9 @@ void systemOff(uint32_t pin, uint8_t wake_logic)
|
||||
// NRF_POWER->RAM[i].POWERCLR = 0x03UL;
|
||||
// }
|
||||
|
||||
#if 0
|
||||
// pin 0 & 1 is for XTAL
|
||||
for(int i=2; i<PINS_COUNT; i++)
|
||||
{
|
||||
pinMode(i, INPUT);
|
||||
}
|
||||
#endif
|
||||
|
||||
pinMode(pin, wake_logic ? INPUT_PULLDOWN : INPUT_PULLUP);
|
||||
NRF_GPIO->PIN_CNF[pin] |= ((uint32_t) (wake_logic ? GPIO_PIN_CNF_SENSE_High : GPIO_PIN_CNF_SENSE_Low) << GPIO_PIN_CNF_SENSE_Pos);
|
||||
|
||||
*digitalPinCnfRegister(pin) |= ((wake_logic ? GPIO_PIN_CNF_SENSE_High : GPIO_PIN_CNF_SENSE_Low) << GPIO_PIN_CNF_SENSE_Pos);
|
||||
|
||||
uint8_t sd_en;
|
||||
(void) sd_softdevice_is_enabled(&sd_en);
|
||||
|
||||
+34
-39
@@ -31,45 +31,45 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
|
||||
return;
|
||||
}
|
||||
|
||||
ulPin = g_ADigitalPinMap[ulPin];
|
||||
// ulPin = g_ADigitalPinMap[ulPin];
|
||||
|
||||
// Set pin mode according to chapter '22.6.3 I/O Pin Configuration'
|
||||
switch ( ulMode )
|
||||
{
|
||||
case INPUT:
|
||||
// Set pin to input mode
|
||||
NRF_GPIO->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);
|
||||
*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 ;
|
||||
|
||||
case INPUT_PULLUP:
|
||||
// Set pin to input mode with pull-up resistor enabled
|
||||
NRF_GPIO->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);
|
||||
*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 ;
|
||||
|
||||
case INPUT_PULLDOWN:
|
||||
// Set pin to input mode with pull-down resistor enabled
|
||||
NRF_GPIO->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);
|
||||
*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 ;
|
||||
|
||||
case OUTPUT:
|
||||
// Set pin to output mode
|
||||
NRF_GPIO->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);
|
||||
*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 ;
|
||||
|
||||
default:
|
||||
@@ -84,20 +84,19 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
|
||||
return;
|
||||
}
|
||||
|
||||
ulPin = g_ADigitalPinMap[ulPin];
|
||||
// ulPin = g_ADigitalPinMap[ulPin];
|
||||
NRF_GPIO_Type* nrf_port = (NRF_GPIO_Type*) digitalPinToPort(ulPin);
|
||||
|
||||
switch ( ulVal )
|
||||
{
|
||||
case LOW:
|
||||
NRF_GPIO->OUTCLR = (1UL << ulPin);
|
||||
nrf_port->OUTCLR = digitalPinToBitMask(ulPin);
|
||||
break ;
|
||||
|
||||
default:
|
||||
NRF_GPIO->OUTSET = (1UL << ulPin);
|
||||
nrf_port->OUTSET = digitalPinToBitMask(ulPin);
|
||||
break ;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
int digitalRead( uint32_t ulPin )
|
||||
@@ -106,17 +105,20 @@ int digitalRead( uint32_t ulPin )
|
||||
return 0;
|
||||
}
|
||||
|
||||
ulPin = g_ADigitalPinMap[ulPin];
|
||||
// ulPin = g_ADigitalPinMap[ulPin];
|
||||
|
||||
// Return bit in NRF_GPIO->OUT or NRF_GPIO->IN depending on configured direction
|
||||
return bitRead(NRF_GPIO->PIN_CNF[ulPin], GPIO_PIN_CNF_DIR_Pos) ? bitRead(NRF_GPIO->OUT, ulPin) : bitRead(NRF_GPIO->IN, 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);
|
||||
}
|
||||
|
||||
int digitalToggle( uint32_t pin )
|
||||
void digitalToggle( uint32_t pin )
|
||||
{
|
||||
int state = 1 - (((NRF_GPIO->OUT >> pin) & 1UL) ? HIGH : LOW);
|
||||
int state = 1 - digitalRead(pin);
|
||||
digitalWrite(pin, state);
|
||||
return state;
|
||||
}
|
||||
|
||||
void ledOn(uint32_t pin)
|
||||
@@ -129,13 +131,6 @@ void ledOff(uint32_t pin)
|
||||
digitalWrite(pin, 1-LED_STATE_ON);
|
||||
}
|
||||
|
||||
int ledToggle( uint32_t pin )
|
||||
{
|
||||
int state = digitalToggle(pin);
|
||||
|
||||
return (state == LED_STATE_ON) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -64,11 +64,10 @@ extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ;
|
||||
*/
|
||||
extern int digitalRead( uint32_t ulPin ) ;
|
||||
|
||||
extern int digitalToggle( uint32_t pin );
|
||||
extern void digitalToggle( uint32_t pin );
|
||||
|
||||
void ledOn(uint32_t pin);
|
||||
void ledOff(uint32_t pin);
|
||||
int ledToggle( uint32_t pin );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ setLoopStacksize KEYWORD2
|
||||
|
||||
ledOn KEYWORD2
|
||||
ledOff KEYWORD2
|
||||
ledToggle KEYWORD2
|
||||
|
||||
printf KEYWORD2
|
||||
printBuffer KEYWORD2
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup() {
|
||||
// initialize digital pin LED_BUILTIN as an output.
|
||||
pinMode(LED_BLUE, OUTPUT);
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
|
||||
@@ -33,7 +33,7 @@ extern "C"
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
ledToggle(LED_RED);
|
||||
digitalToggle(LED_RED);
|
||||
}
|
||||
|
||||
} // extern C
|
||||
|
||||
@@ -67,7 +67,7 @@ void adafruit_soc_task(void* arg);
|
||||
static void bluefruit_blinky_cb( TimerHandle_t xTimer )
|
||||
{
|
||||
(void) xTimer;
|
||||
ledToggle(LED_BLUE);
|
||||
digitalToggle(LED_BLUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,17 +43,17 @@ void TwoWire::begin(void) {
|
||||
//Master Mode
|
||||
master = true;
|
||||
|
||||
NRF_GPIO->PIN_CNF[_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_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);
|
||||
|
||||
NRF_GPIO->PIN_CNF[_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);
|
||||
*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);
|
||||
|
||||
_p_twim->FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K100;
|
||||
_p_twim->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
|
||||
@@ -69,17 +69,17 @@ void TwoWire::begin(uint8_t address) {
|
||||
//Slave mode
|
||||
master = false;
|
||||
|
||||
NRF_GPIO->PIN_CNF[_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_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);
|
||||
|
||||
NRF_GPIO->PIN_CNF[_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);
|
||||
*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);
|
||||
|
||||
_p_twis->ADDRESS[0] = address;
|
||||
_p_twis->CONFIG = TWIS_CONFIG_ADDRESS0_Msk;
|
||||
|
||||
Reference in new issue
Block a user