@@ -29,50 +29,44 @@ extern "C" {
2929
3030#include " Wire.h"
3131
32- #define GPIO_PORT0 ((NRF_GPIO_Type*) 0x50000000UL )
33- #define GPIO_PORT1 ((NRF_GPIO_Type*) 0x50000300UL )
34-
35- static volatile uint32_t * pincfg_reg (uint32_t pin) {
36- if (pin < 32 ) {
37- return &GPIO_PORT0->PIN_CNF [pin];
38- } else {
39- return &GPIO_PORT1->PIN_CNF [pin & 0x1F ];
40- }
41- }
42-
4332TwoWire::TwoWire (NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn, uint8_t pinSDA, uint8_t pinSCL)
4433{
4534 this ->_p_twim = p_twim;
4635 this ->_p_twis = p_twis;
4736 this ->_IRQn = IRQn;
48- this ->_uc_pinSDA = g_ADigitalPinMap[ pinSDA] ;
49- this ->_uc_pinSCL = g_ADigitalPinMap[ pinSCL] ;
37+ this ->_uc_pinSDA = pinSDA;
38+ this ->_uc_pinSCL = pinSCL;
5039 transmissionBegun = false ;
5140}
5241
5342#ifdef ARDUINO_GENERIC
5443void TwoWire::setPins (uint8_t pinSDA, uint8_t pinSCL)
5544{
56- this ->_uc_pinSDA = g_ADigitalPinMap[ pinSDA] ;
57- this ->_uc_pinSCL = g_ADigitalPinMap[ pinSCL] ;
45+ this ->_uc_pinSDA = pinSDA;
46+ this ->_uc_pinSCL = pinSCL;
5847}
5948#endif // ARDUINO_GENERIC
6049
6150void TwoWire::begin (void ) {
6251 // Master Mode
6352 master = true ;
6453
65- *pincfg_reg (_uc_pinSCL) = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
66- | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
67- | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
68- | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
69- | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
54+ NRF_GPIO_Type* portSCL = digitalPinToPort (_uc_pinSCL);
55+ NRF_GPIO_Type* portSDA = digitalPinToPort (_uc_pinSDA);
56+ uint32_t pinSCL = digitalPinToPin (_uc_pinSCL);
57+ uint32_t pinSDA = digitalPinToPin (_uc_pinSDA);
58+
59+ portSCL->PIN_CNF [pinSCL] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
60+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
61+ | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
62+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
63+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
7064
71- * pincfg_reg (_uc_pinSDA) = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
72- | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
73- | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
74- | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
75- | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
65+ portSDA-> PIN_CNF [pinSDA] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
66+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
67+ | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
68+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
69+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
7670
7771 _p_twim->FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K100;
7872 _p_twim->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
@@ -88,17 +82,23 @@ void TwoWire::begin(uint8_t address) {
8882 // Slave mode
8983 master = false ;
9084
91- *pincfg_reg (_uc_pinSCL) = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
92- | ((uint32_t )GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
93- | ((uint32_t )GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
94- | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
95- | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
96-
97- *pincfg_reg (_uc_pinSDA) = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
98- | ((uint32_t )GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
99- | ((uint32_t )GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
100- | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
101- | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
85+ NRF_GPIO_Type* portSCL = digitalPinToPort (_uc_pinSCL);
86+ NRF_GPIO_Type* portSDA = digitalPinToPort (_uc_pinSDA);
87+ uint32_t pinSCL = digitalPinToPin (_uc_pinSCL);
88+ uint32_t pinSDA = digitalPinToPin (_uc_pinSDA);
89+
90+
91+ portSCL->PIN_CNF [pinSCL] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
92+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
93+ | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
94+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
95+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
96+
97+ portSDA->PIN_CNF [pinSDA] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
98+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
99+ | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
100+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
101+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
102102
103103 _p_twis->ADDRESS [0 ] = address;
104104 _p_twis->CONFIG = TWIS_CONFIG_ADDRESS0_Msk;
0 commit comments