Skip to content

Commit ec3cb2f

Browse files
Mikfbraghiroli
authored andcommitted
Added Step-up control pin.
Two user function are added in the core. At the SME initialization the step-up is shutdown.
1 parent 42fede9 commit ec3cb2f

File tree

3 files changed

+93
-36
lines changed

3 files changed

+93
-36
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,26 @@ const PinDescription g_APinDescription[]=
225225

226226
/*
227227
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
228-
* | | I/O Exte | | |
228+
* | | I/O Extension | | |
229229
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
230230
* | 48 | IO_EXT_RST | PA13 | | EXTINT[13] SERCOM2/ PAD[1] SERCOM4/ PAD[1] TCC2/WO[1] TCC0/ WO[7] AC/CMP[1]
231-
* | 49 | IO_EXT_INT | PB06 | |EXTINT[6] AIN[14] Y[12]
231+
* | 49 | IO_EXT_INT | PB06 | | EXTINT[6] AIN[14] Y[12]
232232
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
233233
*/
234234
{ PORTA, 13, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM2_CH1, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // TCC2/WO[1]
235235
{ PORTB, 06, PIO_ANALOG, PIN_ATTR_ANALOG, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC/AIN[14]
236+
237+
/*
238+
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
239+
* | | Step-up PWR | | |
240+
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
241+
* | 50 | EXT_PWR | PB04 | | EXTINT[4] AIN[12] Y[10]
242+
* | 51 | REG_ON | PB05 | | EXTINT[5] AIN[13] Y[11]
243+
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
244+
*/
245+
{ PORTB, 4, PIO_INPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4}, // used as input only
246+
//{ PORTB, 4, PIO_INPUT_PULLUP, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // ADC/AIN[0]
247+
{ PORTB, 5, PIO_OUTPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // used as output only
236248
} ;
237249

238250

@@ -330,3 +342,17 @@ int button1IsPressed(void) {
330342
int button2IsPressed(void) {
331343
return !digitalRead(PIN_SME_BUTTON2);
332344
}
345+
346+
347+
bool isOnBattery(void) {
348+
return !digitalRead(PIN_EXT_PWR);
349+
}
350+
351+
352+
void setStepUp(uint32_t on) {
353+
if (on) {
354+
digitalWrite(PIN_REG_ON, HIGH);
355+
} else {
356+
digitalWrite(PIN_REG_ON, LOW);
357+
}
358+
}

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

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*----------------------------------------------------------------------------*/
3636

3737
#include "WVariant.h"
38+
#include <stdbool.h>
3839

3940
#ifdef __cplusplus
4041
#include "SERCOM.h"
@@ -93,7 +94,11 @@ extern "C"
9394
#define PIN_IO_EXT_INT (49u)
9495

9596

96-
// I/O Extender
97+
// Step-Up Power
98+
#define PIN_EXT_PWR (50u)
99+
#define PIN_REG_ON (51u)
100+
101+
// User Button
97102
#define PIN_SME_BUTTON1 (41u)
98103
#define PIN_SME_BUTTON2 (42u)
99104

@@ -180,12 +185,14 @@ static const uint8_t SCK = PIN_SPI_SCK ;
180185
/*
181186
RGB wrapper function
182187
These functions has been created for a more comfortable use
183-
because internally wrap the inversion of the HIGH, LOW meaning
184-
185-
Using these function it remain the same Arduino User Experience to light a led
186-
HIGH = Light ON
187-
LOW = Light OFF
188-
188+
because internally wrap the inversion of the HIGH, LOW meaning.
189+
Using these function it remain the same Arduino User Experience to light a led.
190+
191+
parameter:
192+
value = the light intensity. It could be
193+
HIGH = light to the maximum level
194+
LOW = switch off the Led
195+
1..255 = pwm value for different level of light
189196
*/
190197
void ledGreenLight(uint32_t value);
191198
void ledRedLight(uint32_t value);
@@ -214,6 +221,25 @@ void ledYellowTwoLight(uint32_t value);
214221
int button1IsPressed(void);
215222
int button2IsPressed(void);
216223

224+
225+
/*
226+
Enable/Disable the StepUp
227+
228+
param:
229+
true = Step-up the Battery Power
230+
false= Do not Step-up the Battery Power
231+
*/
232+
void setStepUp(uint32_t on);
233+
234+
/*
235+
Return the information if the StepUp is enabled
236+
237+
return:
238+
true= the StepUp is running
239+
false = the Sme is not under StepUp Power
240+
*/
241+
bool isOnBattery(void);
242+
217243
#ifdef __cplusplus
218244
}
219245
#endif

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ See the GNU Lesser General Public License for more details.
1515
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
18-
*/
18+
*/
1919

2020
#include <Arduino.h>
21-
//#include "../../../../arduino/samd/libraries/Wire/Wire.h"
2221
#include "WireIoExt.h"
2322

2423
static const uint32_t TWI_CLOCK_SME = 100000;
@@ -95,15 +94,15 @@ static bool writeRegister(byte _address, byte regToWrite, byte dataToWrite)
9594
return (errorNo == 0);
9695
}
9796

98-
uint8_t resetsDbg[2];
99-
uint8_t actual[2];
100-
101-
uint8_t smeInitError=0xFF;
97+
uint8_t resetsDbg[2];
98+
uint8_t actual[2];
99+
100+
uint8_t smeInitError=0xFF;
102101
static void ioExtenderInit(void) {
103102
WireTemp.begin();
104103

105104

106-
// first test the I2C bus
105+
// first test the I2C bus
107106
uint8_t data = readRegister(HTS221_ADDRESS, WHO_AM_I);
108107
if (data == WHO_AM_I_RETURN){
109108
smeInitError = 0;
@@ -115,35 +114,35 @@ static void ioExtenderInit(void) {
115114
if (writeRegister( TCA6416A_ADDRESS, CONFIG_PORT_1, CONF_PORT_1)!=false){
116115
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1, INIT_P1); // keep the resets High
117116
}
118-
117+
119118
// wait a while
120119
delay(20);
121120
resetsDbg[0]=0;
122121
resetsDbg[1]=0;
123-
124-
122+
123+
125124
actual[0] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0);
126125
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0, (actual[0]&~BLE_RESET_PIN));
127126
resetsDbg[0] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0);
128-
127+
129128
if ((actual[1] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1)) != false) {
130129
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1, (actual[1]&(~GPS_RESET_PIN) &(~SFX_WAKEUP_PIN)));
131130
resetsDbg[1] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1);
132131
}
133-
132+
134133
// wait a while
135-
delay(20);
134+
delay(20);
136135

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;
136+
// move the reset high
137+
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0, actual[0]);
138+
resetsDbg[0] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_0);
139+
140+
writeRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1, actual[1]);
141+
resetsDbg[1] = readRegister( TCA6416A_ADDRESS, OUTPUT_PORT_1);
142+
143+
} else {
144+
145+
smeInitError = 1;
147146
}
148147

149148
}
@@ -164,17 +163,23 @@ void initVariant() {
164163
// initialize button1 & button2 as input
165164
pinMode(PIN_SME_BUTTON1, INPUT_PULLUP);
166165
pinMode(PIN_SME_BUTTON2, INPUT_PULLUP);
167-
168-
166+
167+
169168
// initialize RGB LED
170169
LED_GREEN_INIT;
171170
LED_RED_INIT;
172171
LED_BLUE_INIT;
173172
ledGreenLight(LOW);
174173
ledBlueLight(LOW);
175174
ledRedLight(LOW);
176-
177-
175+
176+
// initialize The EXT_PWR Pin as input
177+
// it will be HIGH when the battery is connected
178+
pinMode(PIN_EXT_PWR, INPUT);
179+
// initialize the SetpUp to Disable
180+
pinMode(PIN_REG_ON, OUTPUT);
181+
setStepUp(LOW);
182+
178183
// initialize the IO_Extender
179184
ioExtenderInit();
180185
}

0 commit comments

Comments
 (0)