Skip to content

Commit

Permalink
[WIP] I2C UART PWM proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Mar 31, 2021
1 parent 8a49d2e commit ad18b96
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions PortentaBreakoutCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "Arduino.h"
#include "pins_arduino.h"
#include "mbed.h"
#include "Wire.h"

#define LAST_ARDUINO_PIN_NUMBER LEDB + 1
typedef enum {
Expand Down Expand Up @@ -166,6 +167,69 @@ typedef enum {
USB_EN = -1
} breakoutPin;

class BreakoutI2CClass {
public:
MbedI2C BUS_0;
MbedI2C BUS_1;
MbedI2C BUS_2;
BreakoutI2CClass() : BUS_0(I2C_SDA_0, I2C_SCL_0),
BUS_1(I2C_SDA_1, I2C_SCL_1),
BUS_2(I2C_SDA_2, I2C_SCL_2)
{
}
};

class BreakoutUARTClass {
public:
UART BUS_0;
UART BUS_1;
UART BUS_2;
UART BUS_3;
BreakoutUARTClass() : BUS_0(UART0_TX, UART0_RX, UART0_RTS, UART0_CTS),
BUS_1(UART1_TX, UART1_RX, UART1_RTS, UART1_CTS),
BUS_2(UART2_TX, UART2_RX, UART2_RTS, UART2_CTS),
BUS_3(UART3_TX, UART3_RX, UART3_RTS, UART3_CTS)
{
}
};

class PWM {
breakoutPin pin;
mbed::PwmOut *pwm;
public:
PWM(breakoutPin pin): pin(pin) {
}
void begin(unsigned int period, unsigned int duty) {
if (pwm == NULL) {
pwm = new mbed::PwmOut((PinName)pin);
pwm->period(period);
pwm->write(duty);
} else {
pwm->period(period);
pwm->write(duty);
}
}
~PWM() {
delete pwm;
}

void start (void) {
pwm->resume();
}
void stop (void) {
pwm->suspend();
}
};

class BreakoutPWMClass {
public:
PWM PWM_0;
PWM PWM_1;
BreakoutPWMClass() : PWM_0(PWM0), PWM_1(PWM1)
{
}
};

class BreakoutCarrierClass {
public:
int pinMode(breakoutPin pin, PinMode mode) {
Expand All @@ -188,6 +252,17 @@ class BreakoutCarrierClass {
}
return -1;
}
//Option 1
BreakoutI2CClass I2C;
// Option 2
MbedI2C I2C_0;
MbedI2C I2C_1;
MbedI2C I2C_2;
BreakoutCarrierClass() : I2C_0(I2C_SDA_0,I2C_SCL_0), I2C_1(I2C_SDA_1,I2C_SCL_1), I2C_2(I2C_SDA_2,I2C_SCL_2)
{
}
BreakoutUARTClass UART;
BreakoutPWMClass PWM;
};

BreakoutCarrierClass Breakout;
Expand Down

0 comments on commit ad18b96

Please sign in to comment.