Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-nRF5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-nRF5
Commits
5eebc713
Commit
5eebc713
authored
Mar 27, 2016
by
Sandeep Mistry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve variant structure
parent
b4dc7c70
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
214 additions
and
168 deletions
+214
-168
cores/nRF52/Uart.cpp
cores/nRF52/Uart.cpp
+2
-2
cores/nRF52/WVariant.h
cores/nRF52/WVariant.h
+2
-0
cores/nRF52/wiring_analog.c
cores/nRF52/wiring_analog.c
+20
-0
cores/nRF52/wiring_digital.c
cores/nRF52/wiring_digital.c
+18
-0
libraries/SPI/SPI.cpp
libraries/SPI/SPI.cpp
+4
-4
libraries/Wire/Wire.cpp
libraries/Wire/Wire.cpp
+3
-3
variants/nRF52DK/pca10040.h
variants/nRF52DK/pca10040.h
+0
-154
variants/nRF52DK/pins_arduino.h
variants/nRF52DK/pins_arduino.h
+17
-0
variants/nRF52DK/variant.cpp
variants/nRF52DK/variant.cpp
+40
-1
variants/nRF52DK/variant.h
variants/nRF52DK/variant.h
+108
-4
No files found.
cores/nRF52/Uart.cpp
View file @
5eebc713
...
...
@@ -24,8 +24,8 @@ Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pi
{
nrfUart
=
_nrfUart
;
IRQn
=
_IRQn
;
uc_pinRX
=
_pinRX
;
uc_pinTX
=
_pinTX
;
uc_pinRX
=
g_ADigitalPinMap
[
_pinRX
]
;
uc_pinTX
=
g_ADigitalPinMap
[
_pinTX
]
;
}
void
Uart
::
begin
(
unsigned
long
baudrate
)
...
...
cores/nRF52/WVariant.h
View file @
5eebc713
...
...
@@ -24,6 +24,8 @@
extern
"C"
{
#endif
extern
const
uint32_t
g_ADigitalPinMap
[]
;
#ifdef __cplusplus
}
// extern "C"
#endif
cores/nRF52/wiring_analog.c
View file @
5eebc713
...
...
@@ -102,7 +102,17 @@ uint32_t analogRead( uint32_t ulPin )
uint32_t
resolution
;
nrf_saadc_value_t
value
;
if
(
ulPin
>=
PINS_COUNT
)
{
return
0
;
}
ulPin
=
g_ADigitalPinMap
[
ulPin
];
switch
(
ulPin
)
{
case
2
:
pin
=
NRF_SAADC_INPUT_AIN0
;
break
;
case
3
:
pin
=
NRF_SAADC_INPUT_AIN1
;
break
;
...
...
@@ -111,6 +121,10 @@ uint32_t analogRead( uint32_t ulPin )
pin
=
NRF_SAADC_INPUT_AIN2
;
break
;
case
5
:
pin
=
NRF_SAADC_INPUT_AIN3
;
break
;
case
28
:
pin
=
NRF_SAADC_INPUT_AIN4
;
break
;
...
...
@@ -187,6 +201,12 @@ uint32_t analogRead( uint32_t ulPin )
// to digital output.
void
analogWrite
(
uint32_t
ulPin
,
uint32_t
ulValue
)
{
if
(
ulPin
>=
PINS_COUNT
)
{
return
;
}
ulPin
=
g_ADigitalPinMap
[
ulPin
];
for
(
int
i
=
0
;
i
<
PWM_COUNT
;
i
++
)
{
if
(
pwmChannelPins
[
i
]
==
NRF_PWM_PIN_NOT_CONNECTED
||
pwmChannelPins
[
i
]
==
ulPin
)
{
pwmChannelPins
[
i
]
=
ulPin
;
...
...
cores/nRF52/wiring_digital.c
View file @
5eebc713
...
...
@@ -26,6 +26,12 @@ extern "C" {
void
pinMode
(
uint32_t
ulPin
,
uint32_t
ulMode
)
{
if
(
ulPin
>=
PINS_COUNT
)
{
return
;
}
ulPin
=
g_ADigitalPinMap
[
ulPin
];
// Set pin mode according to chapter '22.6.3 I/O Pin Configuration'
switch
(
ulMode
)
{
...
...
@@ -57,6 +63,12 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
void
digitalWrite
(
uint32_t
ulPin
,
uint32_t
ulVal
)
{
if
(
ulPin
>=
PINS_COUNT
)
{
return
;
}
ulPin
=
g_ADigitalPinMap
[
ulPin
];
switch
(
ulVal
)
{
case
LOW
:
...
...
@@ -73,6 +85,12 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
int
digitalRead
(
uint32_t
ulPin
)
{
if
(
ulPin
>=
PINS_COUNT
)
{
return
0
;
}
ulPin
=
g_ADigitalPinMap
[
ulPin
];
return
nrf_gpio_pin_read
(
ulPin
)
?
HIGH
:
LOW
;
}
...
...
libraries/SPI/SPI.cpp
View file @
5eebc713
...
...
@@ -35,9 +35,9 @@ SPIClass::SPIClass(NRF_SPI_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, u
_p_spi
=
p_spi
;
// pins
_uc_pinMiso
=
uc_pinMISO
;
_uc_pinSCK
=
uc_pinSCK
;
_uc_pinMosi
=
uc_pinMOSI
;
_uc_pinMiso
=
g_ADigitalPinMap
[
uc_pinMISO
]
;
_uc_pinSCK
=
g_ADigitalPinMap
[
uc_pinSCK
]
;
_uc_pinMosi
=
g_ADigitalPinMap
[
uc_pinMOSI
]
;
_dataMode
=
NRF_SPI_MODE_0
;
_bitOrder
=
NRF_SPI_BIT_ORDER_MSB_FIRST
;
...
...
@@ -185,4 +185,4 @@ void SPIClass::detachInterrupt() {
// Should be disableInterrupt()
}
SPIClass
SPI
(
NRF_SPI0
,
24
,
25
,
23
);
SPIClass
SPI
(
NRF_SPI0
,
PIN_SPI_MISO
,
PIN_SPI_SCK
,
PIN_SPI_MOSI
);
libraries/Wire/Wire.cpp
View file @
5eebc713
...
...
@@ -33,8 +33,8 @@ TwoWire::TwoWire(NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn,
this
->
_p_twim
=
p_twim
;
this
->
_p_twis
=
p_twis
;
this
->
_IRQn
=
IRQn
;
this
->
_uc_pinSDA
=
pinSDA
;
this
->
_uc_pinSCL
=
pinSCL
;
this
->
_uc_pinSDA
=
g_ADigitalPinMap
[
pinSDA
]
;
this
->
_uc_pinSCL
=
g_ADigitalPinMap
[
pinSCL
]
;
transmissionBegun
=
false
;
}
...
...
@@ -342,7 +342,7 @@ void TwoWire::onService(void)
}
}
TwoWire
Wire
(
NRF_TWIM0
,
NRF_TWIS0
,
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn
,
26
,
27
);
TwoWire
Wire
(
NRF_TWIM0
,
NRF_TWIS0
,
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn
,
PIN_WIRE_SDA
,
PIN_WIRE_SCL
);
extern
"C"
{
...
...
variants/nRF52DK/pca10040.h
deleted
100755 → 0
View file @
b4dc7c70
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
#ifndef PCA10040_H
#define PCA10040_H
// LEDs definitions for PCA10040
#define LEDS_NUMBER 4
#define LED_START 17
#define LED_1 17
#define LED_2 18
#define LED_3 19
#define LED_4 20
#define LED_STOP 20
#define LEDS_LIST { LED_1, LED_2, LED_3, LED_4 }
#define BSP_LED_0 LED_1
#define BSP_LED_1 LED_2
#define BSP_LED_2 LED_3
#define BSP_LED_3 LED_4
#define BSP_LED_0_MASK (1<<BSP_LED_0)
#define BSP_LED_1_MASK (1<<BSP_LED_1)
#define BSP_LED_2_MASK (1<<BSP_LED_2)
#define BSP_LED_3_MASK (1<<BSP_LED_3)
#define LEDS_MASK (BSP_LED_0_MASK | BSP_LED_1_MASK | BSP_LED_2_MASK | BSP_LED_3_MASK)
/* all LEDs are lit when GPIO is low */
#define LEDS_INV_MASK LEDS_MASK
#define BUTTONS_NUMBER 4
#define BUTTON_START 13
#define BUTTON_1 13
#define BUTTON_2 14
#define BUTTON_3 15
#define BUTTON_4 16
#define BUTTON_STOP 16
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
#define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4 }
#define BSP_BUTTON_0 BUTTON_1
#define BSP_BUTTON_1 BUTTON_2
#define BSP_BUTTON_2 BUTTON_3
#define BSP_BUTTON_3 BUTTON_4
#define BSP_BUTTON_0_MASK (1<<BSP_BUTTON_0)
#define BSP_BUTTON_1_MASK (1<<BSP_BUTTON_1)
#define BSP_BUTTON_2_MASK (1<<BSP_BUTTON_2)
#define BSP_BUTTON_3_MASK (1<<BSP_BUTTON_3)
#define BUTTONS_MASK 0x001E0000
#define RX_PIN_NUMBER 8
#define TX_PIN_NUMBER 6
#define CTS_PIN_NUMBER 7
#define RTS_PIN_NUMBER 5
#define HWFC true
#define SPIS_MISO_PIN 28 // SPI MISO signal.
#define SPIS_CSN_PIN 12 // SPI CSN signal.
#define SPIS_MOSI_PIN 25 // SPI MOSI signal.
#define SPIS_SCK_PIN 29 // SPI SCK signal.
#define SPIM0_SCK_PIN 29 // SPI clock GPIO pin number.
#define SPIM0_MOSI_PIN 25 // SPI Master Out Slave In GPIO pin number.
#define SPIM0_MISO_PIN 28 // SPI Master In Slave Out GPIO pin number.
#define SPIM0_SS_PIN 12 // SPI Slave Select GPIO pin number.
#define SPIM1_SCK_PIN 2 // SPI clock GPIO pin number.
#define SPIM1_MOSI_PIN 3 // SPI Master Out Slave In GPIO pin number.
#define SPIM1_MISO_PIN 4 // SPI Master In Slave Out GPIO pin number.
#define SPIM1_SS_PIN 5 // SPI Slave Select GPIO pin number.
#define SPIM2_SCK_PIN 12 // SPI clock GPIO pin number.
#define SPIM2_MOSI_PIN 13 // SPI Master Out Slave In GPIO pin number.
#define SPIM2_MISO_PIN 14 // SPI Master In Slave Out GPIO pin number.
#define SPIM2_SS_PIN 15 // SPI Slave Select GPIO pin number.
// serialization APPLICATION board - temp. setup for running serialized MEMU tests
#define SER_APP_RX_PIN 23 // UART RX pin number.
#define SER_APP_TX_PIN 24 // UART TX pin number.
#define SER_APP_CTS_PIN 2 // UART Clear To Send pin number.
#define SER_APP_RTS_PIN 25 // UART Request To Send pin number.
#define SER_APP_SPIM0_SCK_PIN 27 // SPI clock GPIO pin number.
#define SER_APP_SPIM0_MOSI_PIN 2 // SPI Master Out Slave In GPIO pin number
#define SER_APP_SPIM0_MISO_PIN 26 // SPI Master In Slave Out GPIO pin number
#define SER_APP_SPIM0_SS_PIN 23 // SPI Slave Select GPIO pin number
#define SER_APP_SPIM0_RDY_PIN 25 // SPI READY GPIO pin number
#define SER_APP_SPIM0_REQ_PIN 24 // SPI REQUEST GPIO pin number
// serialization CONNECTIVITY board
#define SER_CON_RX_PIN 24 // UART RX pin number.
#define SER_CON_TX_PIN 23 // UART TX pin number.
#define SER_CON_CTS_PIN 25 // UART Clear To Send pin number. Not used if HWFC is set to false.
#define SER_CON_RTS_PIN 2 // UART Request To Send pin number. Not used if HWFC is set to false.
#define SER_CON_SPIS_SCK_PIN 27 // SPI SCK signal.
#define SER_CON_SPIS_MOSI_PIN 2 // SPI MOSI signal.
#define SER_CON_SPIS_MISO_PIN 26 // SPI MISO signal.
#define SER_CON_SPIS_CSN_PIN 23 // SPI CSN signal.
#define SER_CON_SPIS_RDY_PIN 25 // SPI READY GPIO pin number.
#define SER_CON_SPIS_REQ_PIN 24 // SPI REQUEST GPIO pin number.
#define SER_CONN_CHIP_RESET_PIN 11 // Pin used to reset connectivity chip
// Arduino board mappings
#define ARDUINO_SCL_PIN 27 // SCL signal pin
#define ARDUINO_SDA_PIN 26 // SDA signal pin
#define ARDUINO_AREF_PIN 2 // Aref pin
#define ARDUINO_13_PIN 25 // Digital pin 13
#define ARDUINO_12_PIN 24 // Digital pin 12
#define ARDUINO_11_PIN 23 // Digital pin 11
#define ARDUINO_10_PIN 22 // Digital pin 10
#define ARDUINO_9_PIN 20 // Digital pin 9
#define ARDUINO_8_PIN 19 // Digital pin 8
#define ARDUINO_7_PIN 18 // Digital pin 7
#define ARDUINO_6_PIN 17 // Digital pin 6
#define ARDUINO_5_PIN 16 // Digital pin 5
#define ARDUINO_4_PIN 15 // Digital pin 4
#define ARDUINO_3_PIN 14 // Digital pin 3
#define ARDUINO_2_PIN 13 // Digital pin 2
#define ARDUINO_1_PIN 12 // Digital pin 1
#define ARDUINO_0_PIN 11 // Digital pin 0
#define ARDUINO_A0_PIN 3 // Analog channel 0
#define ARDUINO_A1_PIN 4 // Analog channel 1
#define ARDUINO_A2_PIN 28 // Analog channel 2
#define ARDUINO_A3_PIN 29 // Analog channel 3
#define ARDUINO_A4_PIN 30 // Analog channel 4
#define ARDUINO_A5_PIN 31 // Analog channel 5
// Low frequency clock source to be used by the SoftDevice
#define NRF_CLOCK_LFCLKSRC {.source = NRF_CLOCK_LF_SRC_XTAL, \
.
rc_ctiv
=
0
,
\
.
rc_temp_ctiv
=
0
,
\
.
xtal_accuracy
=
NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM
}
#endif // PCA10040_H
variants/nRF52DK/pins_arduino.h
0 → 100644
View file @
5eebc713
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// API compatibility
#include "variant.h"
variants/nRF52DK/variant.cpp
View file @
5eebc713
...
...
@@ -18,7 +18,46 @@
#include "variant.h"
Uart
Serial
(
NRF_UART0
,
UARTE0_UART0_IRQn
,
RX_PIN_NUMBER
,
TX_PIN_NUMBER
);
const
uint32_t
g_ADigitalPinMap
[]
=
{
// D0 - D7
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
// D8 - D13
19
,
20
,
22
,
23
,
24
,
25
,
// A0 - A5
3
,
4
,
28
,
29
,
30
,
31
,
// SCL, SDA
27
,
26
,
// RX, TX
8
,
6
,
// AREF
2
};
Uart
Serial
(
NRF_UART0
,
UARTE0_UART0_IRQn
,
PIN_SERIAL_RX
,
PIN_SERIAL_TX
);
extern
"C"
{
...
...
variants/nRF52DK/variant.h
View file @
5eebc713
...
...
@@ -16,10 +16,8 @@
#ifndef _VARIANT_NRF52_DK_
#define _VARIANT_NRF52_DK_
#include "pca10040.h"
/** Master clock frequency */
#define VARIANT_MCK (
16
000000ul)
#define VARIANT_MCK (
64
000000ul)
/*----------------------------------------------------------------------------
* Headers
...
...
@@ -36,6 +34,96 @@ extern "C"
{
#endif // __cplusplus
// Number of pins defined in PinDescription array
#define PINS_COUNT (25u)
#define NUM_DIGITAL_PINS (14u)
#define NUM_ANALOG_INPUTS (6u)
#define NUM_ANALOG_OUTPUTS (0u)
#define digitalPinToPort(P) ( &(NRF_GPIO]) )
#define digitalPinToBitMask(P) ( 1 << g_ADigitalPinMap[P] )
//#define analogInPinToBit(P) ( )
#define portOutputRegister(port) ( &(port->OUTSET) )
#define portInputRegister(port) ( &(port->IN) )
#define portModeRegister(port) ( &(port->DIRSET) )
#define digitalPinHasPWM(P) ( true )
/*
* digitalPinToTimer(..) is AVR-specific and is not defined for nRF52
* architecture. If you need to check if a pin supports PWM you must
* use digitalPinHasPWM(..).
*
* https://github.com/arduino/Arduino/issues/1833
*/
// #define digitalPinToTimer(P)
// Interrupts
#define digitalPinToInterrupt(P) ( P )
// LEDs
#define PIN_LED1 (17)
#define PIN_LED2 (18)
#define PIN_LED3 (19)
#define PIN_LED4 (20)
#define LED_BUILTIN PIN_LED1
// Buttons
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
/*
* Analog pins
*/
#define PIN_A0 (14)
#define PIN_A1 (15)
#define PIN_A2 (16)
#define PIN_A3 (17)
#define PIN_A4 (18)
#define PIN_A5 (19)
static
const
uint8_t
A0
=
PIN_A0
;
static
const
uint8_t
A1
=
PIN_A1
;
static
const
uint8_t
A2
=
PIN_A2
;
static
const
uint8_t
A3
=
PIN_A3
;
static
const
uint8_t
A4
=
PIN_A4
;
static
const
uint8_t
A5
=
PIN_A5
;
#define ADC_RESOLUTION 14
// Other pins
#define PIN_AREF (24)
static
const
uint8_t
AREF
=
PIN_AREF
;
/*
* Serial interfaces
*/
// Serial
#define PIN_SERIAL_RX (22)
#define PIN_SERIAL_TX (23)
/*
* SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12)
#define PIN_SPI_MOSI (11)
#define PIN_SPI_SCK (13)
static
const
uint8_t
SS
=
11
;
static
const
uint8_t
MOSI
=
PIN_SPI_MOSI
;
static
const
uint8_t
MISO
=
PIN_SPI_MISO
;
static
const
uint8_t
SCK
=
PIN_SPI_SCK
;
/*
* Wire Interfaces
*/
#define WIRE_INTERFACES_COUNT 1
#define PIN_WIRE_SDA (20u)
#define PIN_WIRE_SCL (21u)
#ifdef __cplusplus
}
#endif
...
...
@@ -55,6 +143,22 @@ extern Uart Serial;
#endif
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_HARDWARE Serial
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment