Skip to content

Commit c52a3f8

Browse files
fontamiHwfbraghiroli
authored andcommitted
Added IO_EXT register initialization and buttons definition
1 parent e63f95f commit c52a3f8

File tree

2 files changed

+146
-4
lines changed

2 files changed

+146
-4
lines changed

hardware/AMEL/samd/variants/AMEL_SmartEverything/variant.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ extern "C"
8888
#define PIN_LED3 PIN_LED_TXL
8989
#define LED_BUILTIN PIN_LED_13
9090

91-
92-
9391
// I/O Extender
9492
#define PIN_IO_EXT_RST (48u)
9593
#define PIN_IO_EXT_INT (49u)
9694

95+
96+
// I/O Extender
97+
#define PIN_SME_BUTTON1 (41u)
98+
#define PIN_SME_BUTTON2 (42u)
99+
100+
97101
/*
98102
* Analog pins
99103
*/
@@ -173,6 +177,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
173177
#define PIN_USB_DM (29ul)
174178
#define PIN_USB_DP (30ul)
175179

180+
176181
#ifdef __cplusplus
177182
}
178183
#endif
@@ -181,6 +186,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
181186
* Arduino objects - C++ only
182187
*----------------------------------------------------------------------------*/
183188

189+
184190
#ifdef __cplusplus
185191

186192
/* =========================
@@ -223,5 +229,7 @@ extern Uart SigFox;
223229
#define SERIAL_PORT_HARDWARE Serial1
224230
#define SERIAL_PORT_HARDWARE_OPEN Serial1
225231

232+
233+
extern uint8_t smeInitError;
226234
#endif /* _VARIANT_AMEL_SMARTEVERYTHING_ */
227235

hardware/AMEL/samd/variants/AMEL_SmartEverything/variantInit.cpp

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,147 @@ You should have received a copy of the GNU Lesser General Public
1616
License along with this library; if not, write to the Free Software
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
19+
1920
#include <Arduino.h>
21+
//#include "../../../../arduino/samd/libraries/Wire/Wire.h"
22+
#include "WireIoExt.h"
23+
24+
static const uint32_t TWI_CLOCK_SME = 100000;
25+
26+
#define HTS221_ADDRESS 0x5F
27+
//Define a few of the registers that we will be accessing on the HTS221
28+
#define WHO_AM_I 0x0F
29+
#define WHO_AM_I_RETURN 0xBC //This read-only register contains the device identifier, set to BCh
30+
31+
32+
#define TCA6416A_ADDRESS 0x20
33+
#define CONF_PORT_0 0b01111111
34+
#define INIT_P0 0b10000000
35+
36+
#define CONF_PORT_1 0b00110101
37+
#define INIT_P1 0b11001010
38+
#define VALUE_GPS_FORCE_ON 0b10001010
39+
40+
// Protocol PowerOn Default
41+
#define INPUT_PORT_0 0x00 //Read byte xxxx xxxx (undefined)
42+
#define INPUT_PORT_1 0x01 //Read byte xxxx xxxx
43+
#define OUTPUT_PORT_0 0x02 //Read/write byte 1111 1111
44+
#define OUTPUT_PORT_1 0x03 //Read/write byte 1111 1111
45+
#define P_INVERT_PORT_0 0x04 //Read/write byte 0000 0000
46+
#define P_INVERT_PORT_1 0x05 //Read/write byte 0000 0000
47+
#define CONFIG_PORT_0 0x06 //Read/write byte 1111 1111
48+
#define CONFIG_PORT_1 0x07 //Read/write byte 1111 1111
49+
50+
51+
#define _9AX_INT2_A_G_PIN 0x1
52+
#define _9AX_INT1_A_G_PIN 0x2
53+
#define _9AX_INT_M_PIN 0x4
54+
#define _9AX_DRDY_M_PIN 0x8
55+
#define PRE_INT_PIN 0x10
56+
#define ALS_GPIO0_PIN 0x20
57+
#define ALS_GPIO1_PIN 0x40
58+
#define BLE_RESET_PIN 0x80
59+
60+
#define SFX_STDBY_STS_PIN 0x1
61+
#define SFX_RESET_PIN 0x2
62+
#define SFX_RADIO_STS_PIN 0x4
63+
#define SFX_WAKEUP_PIN 0x8
64+
#define NFC_FD_PIN 0x10
65+
#define HUT_DRDY_PIN 0x20
66+
#define GPS_FORCE_ON_PIN 0x40
67+
#define GPS_RESET_PIN 0x80
68+
69+
70+
static byte readRegister(byte _address, byte regToRead)
71+
{
72+
WireTemp.beginTransmission(_address);
73+
WireTemp.write(regToRead);
74+
WireTemp.endTransmission(false); //endTransmission but keep the connection active
75+
76+
WireTemp.requestFrom(_address, 1); //Ask for 1 byte, once done, bus is released by default
77+
78+
while(!WireTemp.available()) ; //Wait for the data to come back
79+
return WireTemp.read(); //Return this one byte
80+
}
81+
82+
// Writes a single byte (dataToWrite) into regToWrite
83+
static bool writeRegister(byte _address, byte regToWrite, byte dataToWrite)
84+
{
85+
WireTemp.beginTransmission(_address);
86+
87+
if (!WireTemp.write(regToWrite)) {
88+
return false;
89+
}
90+
if (!WireTemp.write(dataToWrite)) {
91+
return false;
92+
}
93+
94+
uint8_t errorNo = WireTemp.endTransmission(); //Stop transmitting
95+
return (errorNo == 0);
96+
}
97+
98+
uint8_t resetsDbg[2];
99+
uint8_t actual[2];
100+
101+
uint8_t smeInitError=0xFF;
102+
static void ioExtenderInit(void) {
103+
WireTemp.begin();
104+
105+
106+
// first test the I2C bus
107+
uint8_t data = readRegister(HTS221_ADDRESS, WHO_AM_I);
108+
if (data == WHO_AM_I_RETURN){
109+
smeInitError = 0;
110+
111+
if (writeRegister( TCA6416A_ADDRESS, CONFIG_PORT_0, CONF_PORT_0)!=false) {
112+
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0, INIT_P0); // keep the BLE reset High
113+
}
114+
115+
if (writeRegister( TCA6416A_ADDRESS, CONFIG_PORT_1, CONF_PORT_1)!=false){
116+
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1, INIT_P1); // keep the resets High
117+
}
118+
119+
// wait a while
120+
delay(20);
121+
resetsDbg[0]=0;
122+
resetsDbg[1]=0;
123+
124+
125+
actual[0] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0);
126+
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0, (actual[0]&~BLE_RESET_PIN));
127+
resetsDbg[0] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0);
128+
129+
if ((actual[1] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1)) != false) {
130+
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1, (actual[1]&(~GPS_RESET_PIN) &(~SFX_WAKEUP_PIN)));
131+
resetsDbg[1] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1);
132+
}
133+
134+
// wait a while
135+
delay(20);
136+
137+
// move the reset high
138+
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0, actual[0]);
139+
resetsDbg[0] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0);
140+
141+
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1, actual[1]);
142+
resetsDbg[1] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1);
143+
144+
} else {
145+
146+
smeInitError = 1;
147+
}
148+
149+
}
150+
20151

21152
void initVariant() {
22153
// reset the I/O Extender
23154
pinMode(PIN_IO_EXT_RST, OUTPUT);
24155
digitalWrite(PIN_IO_EXT_RST, LOW);
25156
delay(10); // just wait a while
26-
digitalWrite(PIN_IO_EXT_RST, HIGH);
27-
}
157+
digitalWrite(PIN_IO_EXT_RST, HIGH);
28158

159+
160+
// initialize the IO_Extender
161+
ioExtenderInit();
162+
}

0 commit comments

Comments
 (0)