Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: max32625pico maxim-dev mbed-rtos USBDevice
Fork of PICO_USB_I2C_SPI by
main.cpp
- Committer:
- seanburford
- Date:
- 2017-11-24
- Revision:
- 16:847788f907eb
- Parent:
- 15:9801f08ce0ee
- Child:
- 17:43cc59f768af
File content as of revision 16:847788f907eb:
#include "mbed.h"
#include "rtos.h"
#include "gpio_api.h"
#include "max32625pico.h"
#include "pwrman_regs.h"
static DigitalOut rLED(LED1);
static DigitalOut gLED(LED2);
static DigitalOut bLED(LED3);
int gpioAlternatePullup(PinName name) {
// Enable high resistance pullups per AN6350 section 5.2.4.1
int result = E_NO_ERROR;
unsigned int port = PINNAME_TO_PORT(name);
unsigned int pin = PINNAME_TO_PIN(name);
MXC_IOMAN->wud_req0 |= ((1 << pin) << (port << 3)); // pinmask
if (MXC_IOMAN->wud_ack0 != MXC_IOMAN->wud_req0) {
result = E_BUSY;
}
if (result == E_NO_ERROR) {
MXC_PWRMAN->wud_ctrl = MXC_F_PWRMAN_WUD_CTRL_CTRL_ENABLE;
MXC_PWRMAN->wud_ctrl |= (port * 8) + pin; // Pad select
MXC_PWRMAN->wud_ctrl &= ~(MXC_F_PWRMAN_WUD_CTRL_PAD_MODE);
MXC_PWRMAN->wud_ctrl |= (MXC_E_PWRMAN_PAD_MODE_WEAK_HI_LO <<
MXC_F_PWRMAN_WUD_CTRL_PAD_MODE_POS);
MXC_PWRMAN->wud_pulse0 = 1;
}
MXC_PWRMAN->wud_ctrl = 0;
MXC_IOMAN->wud_req0 = 0;
return result;
}
int main()
{
rLED = LED_ON;
gLED = LED_ON;
bLED = LED_OFF;
MAX32625PICO pico(
MAX32625PICO::IOH_3V3, MAX32625PICO::VIO_IOH, MAX32625PICO::VIO_IOH);
gpioAlternatePullup(P1_6);
gpioAlternatePullup(P1_7);
I2C i2c(P1_6, P1_7);
i2c.frequency(100000);
rLED = LED_OFF;
gLED = LED_OFF;
char dbuf[32];
while(1) {
Thread::wait(15);
if (i2c.read(0x55, dbuf, 8) == 0) {
gLED = !gLED;
} else {
rLED = !rLED;
}
}
}
