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@16:847788f907eb, 2017-11-24 (annotated)
- Committer:
- seanburford
- Date:
- Fri Nov 24 05:37:12 2017 +0000
- Revision:
- 16:847788f907eb
- Parent:
- 15:9801f08ce0ee
- Child:
- 17:43cc59f768af
Remove excess code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| switches | 0:60a522ae2e35 | 1 | #include "mbed.h" |
| switches | 13:fed6ff32bf5d | 2 | #include "rtos.h" |
| switches | 3:aa55728c8e09 | 3 | |
| seanburford | 14:7a4b0f9d1474 | 4 | #include "gpio_api.h" |
| seanburford | 14:7a4b0f9d1474 | 5 | #include "max32625pico.h" |
| seanburford | 15:9801f08ce0ee | 6 | #include "pwrman_regs.h" |
| switches | 5:2436ae0a9eb1 | 7 | |
| seanburford | 14:7a4b0f9d1474 | 8 | static DigitalOut rLED(LED1); |
| seanburford | 14:7a4b0f9d1474 | 9 | static DigitalOut gLED(LED2); |
| seanburford | 14:7a4b0f9d1474 | 10 | static DigitalOut bLED(LED3); |
| switches | 5:2436ae0a9eb1 | 11 | |
| seanburford | 16:847788f907eb | 12 | int gpioAlternatePullup(PinName name) { |
| seanburford | 16:847788f907eb | 13 | // Enable high resistance pullups per AN6350 section 5.2.4.1 |
| seanburford | 15:9801f08ce0ee | 14 | int result = E_NO_ERROR; |
| seanburford | 16:847788f907eb | 15 | unsigned int port = PINNAME_TO_PORT(name); |
| seanburford | 16:847788f907eb | 16 | unsigned int pin = PINNAME_TO_PIN(name); |
| seanburford | 16:847788f907eb | 17 | MXC_IOMAN->wud_req0 |= ((1 << pin) << (port << 3)); // pinmask |
| seanburford | 15:9801f08ce0ee | 18 | if (MXC_IOMAN->wud_ack0 != MXC_IOMAN->wud_req0) { |
| seanburford | 15:9801f08ce0ee | 19 | result = E_BUSY; |
| seanburford | 15:9801f08ce0ee | 20 | } |
| seanburford | 15:9801f08ce0ee | 21 | if (result == E_NO_ERROR) { |
| seanburford | 15:9801f08ce0ee | 22 | MXC_PWRMAN->wud_ctrl = MXC_F_PWRMAN_WUD_CTRL_CTRL_ENABLE; |
| seanburford | 16:847788f907eb | 23 | MXC_PWRMAN->wud_ctrl |= (port * 8) + pin; // Pad select |
| seanburford | 15:9801f08ce0ee | 24 | MXC_PWRMAN->wud_ctrl &= ~(MXC_F_PWRMAN_WUD_CTRL_PAD_MODE); |
| seanburford | 16:847788f907eb | 25 | MXC_PWRMAN->wud_ctrl |= (MXC_E_PWRMAN_PAD_MODE_WEAK_HI_LO << |
| seanburford | 16:847788f907eb | 26 | MXC_F_PWRMAN_WUD_CTRL_PAD_MODE_POS); |
| seanburford | 15:9801f08ce0ee | 27 | MXC_PWRMAN->wud_pulse0 = 1; |
| seanburford | 15:9801f08ce0ee | 28 | } |
| seanburford | 15:9801f08ce0ee | 29 | MXC_PWRMAN->wud_ctrl = 0; |
| seanburford | 15:9801f08ce0ee | 30 | MXC_IOMAN->wud_req0 = 0; |
| seanburford | 15:9801f08ce0ee | 31 | return result; |
| seanburford | 15:9801f08ce0ee | 32 | } |
| seanburford | 15:9801f08ce0ee | 33 | |
| switches | 0:60a522ae2e35 | 34 | int main() |
| switches | 0:60a522ae2e35 | 35 | { |
| switches | 2:57500e991166 | 36 | rLED = LED_ON; |
| switches | 2:57500e991166 | 37 | gLED = LED_ON; |
| switches | 2:57500e991166 | 38 | bLED = LED_OFF; |
| switches | 3:aa55728c8e09 | 39 | |
| seanburford | 14:7a4b0f9d1474 | 40 | MAX32625PICO pico( |
| seanburford | 14:7a4b0f9d1474 | 41 | MAX32625PICO::IOH_3V3, MAX32625PICO::VIO_IOH, MAX32625PICO::VIO_IOH); |
| switches | 0:60a522ae2e35 | 42 | |
| seanburford | 16:847788f907eb | 43 | gpioAlternatePullup(P1_6); |
| seanburford | 16:847788f907eb | 44 | gpioAlternatePullup(P1_7); |
| seanburford | 14:7a4b0f9d1474 | 45 | |
| seanburford | 14:7a4b0f9d1474 | 46 | I2C i2c(P1_6, P1_7); |
| seanburford | 16:847788f907eb | 47 | i2c.frequency(100000); |
| switches | 2:57500e991166 | 48 | |
| switches | 2:57500e991166 | 49 | rLED = LED_OFF; |
| seanburford | 14:7a4b0f9d1474 | 50 | gLED = LED_OFF; |
| switches | 5:2436ae0a9eb1 | 51 | |
| seanburford | 14:7a4b0f9d1474 | 52 | char dbuf[32]; |
| switches | 1:6923b075c8d7 | 53 | while(1) { |
| seanburford | 14:7a4b0f9d1474 | 54 | Thread::wait(15); |
| seanburford | 14:7a4b0f9d1474 | 55 | if (i2c.read(0x55, dbuf, 8) == 0) { |
| seanburford | 14:7a4b0f9d1474 | 56 | gLED = !gLED; |
| seanburford | 14:7a4b0f9d1474 | 57 | } else { |
| seanburford | 14:7a4b0f9d1474 | 58 | rLED = !rLED; |
| seanburford | 14:7a4b0f9d1474 | 59 | } |
| switches | 0:60a522ae2e35 | 60 | } |
| seanburford | 16:847788f907eb | 61 | } |
