Skip to content

Commit

Permalink
Added pmic configuration on nono iot 33 variant
Browse files Browse the repository at this point in the history
added pmic configuration suppoort  on nano iot 33, this is enabled only when a arduino motor carrier board is attached and the realted library is used
  • Loading branch information
Rocketct committed May 26, 2020
1 parent 46f6cad commit f6b5232
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions variants/nano_33_iot/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,86 @@ extern "C" {

const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM]={ TCC0, TCC1, TCC2, TC3, TC4, TC5 } ;

#if defined(__ARDUINOMOTORSHIELD__)
#include "wiring_private.h"

#define PMIC_ADDRESS 0x6B
#define PMIC_REG01 0x01
#define PMIC_REG05 0x05
#define PMIC_REG07 0x07

static inline void enable_battery_charging() {
PERIPH_WIRE.initMasterWIRE(100000);
PERIPH_WIRE.enableWIRE();
pinPeripheral(PIN_WIRE_SDA, g_APinDescription[PIN_WIRE_SDA].ulPinType);
pinPeripheral(PIN_WIRE_SCL, g_APinDescription[PIN_WIRE_SCL].ulPinType);

PERIPH_WIRE.startTransmissionWIRE( PMIC_ADDRESS, WIRE_WRITE_FLAG );
PERIPH_WIRE.sendDataMasterWIRE(PMIC_REG01);
PERIPH_WIRE.sendDataMasterWIRE(0x1B); // Charge Battery + Minimum System Voltage 3.5V
PERIPH_WIRE.prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);

PERIPH_WIRE.disableWIRE();
}

static inline void disable_battery_fet(bool disabled) {
PERIPH_WIRE.initMasterWIRE(100000);
PERIPH_WIRE.enableWIRE();
pinPeripheral(PIN_WIRE_SDA, g_APinDescription[PIN_WIRE_SDA].ulPinType);
pinPeripheral(PIN_WIRE_SCL, g_APinDescription[PIN_WIRE_SCL].ulPinType);

PERIPH_WIRE.startTransmissionWIRE( PMIC_ADDRESS, WIRE_WRITE_FLAG );
PERIPH_WIRE.sendDataMasterWIRE(PMIC_REG07);
// No D+/D– detection + Safety timer not slowed by 2X during input DPM or thermal regulation +
// BAT fet disabled/enabled + charge and bat fault INT
PERIPH_WIRE.sendDataMasterWIRE(0x0B | (disabled ? 0x20 : 0x00));
PERIPH_WIRE.prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);

PERIPH_WIRE.disableWIRE();
}

void disable_watchdog() {
PERIPH_WIRE.initMasterWIRE(100000);
PERIPH_WIRE.enableWIRE();
pinPeripheral(PIN_WIRE_SDA, g_APinDescription[PIN_WIRE_SDA].ulPinType);
pinPeripheral(PIN_WIRE_SCL, g_APinDescription[PIN_WIRE_SCL].ulPinType);

PERIPH_WIRE.startTransmissionWIRE( PMIC_ADDRESS, WIRE_WRITE_FLAG );
PERIPH_WIRE.sendDataMasterWIRE(PMIC_REG05);
PERIPH_WIRE.sendDataMasterWIRE(0x8A); // disable wahcdog
PERIPH_WIRE.prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);

PERIPH_WIRE.disableWIRE();

int DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);

if (DATA == -1) {
return 0;
}

return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA & 0b11001110));
}

#endif


void initVariant() {
#if defined(__ARDUINOMOTORSHIELD__)
pinMode(ADC_BATTERY, OUTPUT);
digitalWrite(ADC_BATTERY, LOW);
delay(10);
pinMode(ADC_BATTERY, INPUT);
delay(100);

bool batteryPresent = analogRead(ADC_BATTERY) > 600;
if (batteryPresent) {
disable_watchdog();
enable_battery_charging();
}
disable_battery_fet(!batteryPresent);
#endif


// NINA - SPI boot
pinMode(NINA_GPIO0, OUTPUT);
digitalWrite(NINA_GPIO0, HIGH);
Expand All @@ -185,6 +264,8 @@ SERCOM sercom3( SERCOM3 ) ;
SERCOM sercom4( SERCOM4 ) ;
SERCOM sercom5( SERCOM5 ) ;



Uart Serial1( &sercom5, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;

void SERCOM5_Handler()
Expand Down

0 comments on commit f6b5232

Please sign in to comment.