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@14:7a4b0f9d1474, 2017-11-20 (annotated)
- Committer:
- seanburford
- Date:
- Mon Nov 20 03:29:34 2017 +0000
- Revision:
- 14:7a4b0f9d1474
- Parent:
- 13:fed6ff32bf5d
- Child:
- 15:9801f08ce0ee
SImple I2C pullup test case
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" |
switches | 5:2436ae0a9eb1 | 6 | |
seanburford | 14:7a4b0f9d1474 | 7 | // #define MAX_GPIO_API 1 |
seanburford | 14:7a4b0f9d1474 | 8 | #define MAX_I2C_API 1 |
switches | 3:aa55728c8e09 | 9 | |
seanburford | 14:7a4b0f9d1474 | 10 | static DigitalOut rLED(LED1); |
seanburford | 14:7a4b0f9d1474 | 11 | static DigitalOut gLED(LED2); |
seanburford | 14:7a4b0f9d1474 | 12 | static DigitalOut bLED(LED3); |
switches | 5:2436ae0a9eb1 | 13 | |
switches | 0:60a522ae2e35 | 14 | int main() |
switches | 0:60a522ae2e35 | 15 | { |
switches | 2:57500e991166 | 16 | rLED = LED_ON; |
switches | 2:57500e991166 | 17 | gLED = LED_ON; |
switches | 2:57500e991166 | 18 | bLED = LED_OFF; |
switches | 3:aa55728c8e09 | 19 | |
seanburford | 14:7a4b0f9d1474 | 20 | MAX32625PICO pico( |
seanburford | 14:7a4b0f9d1474 | 21 | MAX32625PICO::IOH_3V3, MAX32625PICO::VIO_IOH, MAX32625PICO::VIO_IOH); |
switches | 0:60a522ae2e35 | 22 | |
seanburford | 14:7a4b0f9d1474 | 23 | #ifdef MAX_GPIO_API |
seanburford | 14:7a4b0f9d1474 | 24 | gpio_t gpio_p1_6; |
seanburford | 14:7a4b0f9d1474 | 25 | gpio_t gpio_p1_7; |
seanburford | 14:7a4b0f9d1474 | 26 | gpio_init(&gpio_p1_6, P1_6); |
seanburford | 14:7a4b0f9d1474 | 27 | gpio_init(&gpio_p1_7, P1_7); |
seanburford | 14:7a4b0f9d1474 | 28 | // gpio_api.c:104 sets the pin to MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP |
seanburford | 14:7a4b0f9d1474 | 29 | pin_dir_mode(P1_6, PIN_INPUT, PullUp); |
seanburford | 14:7a4b0f9d1474 | 30 | pin_dir_mode(P1_7, PIN_INPUT, PullUp); |
seanburford | 14:7a4b0f9d1474 | 31 | #else |
seanburford | 14:7a4b0f9d1474 | 32 | DigitalInOut(P1_6, PIN_INPUT, PullUp, 1); |
seanburford | 14:7a4b0f9d1474 | 33 | DigitalInOut(P1_7, PIN_INPUT, PullUp, 1); |
seanburford | 14:7a4b0f9d1474 | 34 | #endif |
seanburford | 14:7a4b0f9d1474 | 35 | |
seanburford | 14:7a4b0f9d1474 | 36 | Thread::wait(15); |
seanburford | 14:7a4b0f9d1474 | 37 | |
seanburford | 14:7a4b0f9d1474 | 38 | #ifdef MAX_I2C_API |
seanburford | 14:7a4b0f9d1474 | 39 | i2c_t i2c_o; |
seanburford | 14:7a4b0f9d1474 | 40 | i2c_init(&i2c_o, P1_6, P1_7); |
seanburford | 14:7a4b0f9d1474 | 41 | #else |
seanburford | 14:7a4b0f9d1474 | 42 | I2C i2c(P1_6, P1_7); |
seanburford | 14:7a4b0f9d1474 | 43 | #endif |
switches | 2:57500e991166 | 44 | |
switches | 2:57500e991166 | 45 | rLED = LED_OFF; |
seanburford | 14:7a4b0f9d1474 | 46 | gLED = LED_OFF; |
switches | 5:2436ae0a9eb1 | 47 | |
seanburford | 14:7a4b0f9d1474 | 48 | char dbuf[32]; |
switches | 1:6923b075c8d7 | 49 | while(1) { |
seanburford | 14:7a4b0f9d1474 | 50 | Thread::wait(15); |
seanburford | 14:7a4b0f9d1474 | 51 | #ifdef MAX_I2C_API |
seanburford | 14:7a4b0f9d1474 | 52 | if (i2c_read(&i2c_o, 0x55, dbuf, 8, 1) > 0) { |
seanburford | 14:7a4b0f9d1474 | 53 | #else |
seanburford | 14:7a4b0f9d1474 | 54 | if (i2c.read(0x55, dbuf, 8) == 0) { |
seanburford | 14:7a4b0f9d1474 | 55 | #endif |
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 | } |
switches | 0:60a522ae2e35 | 61 | } |
switches | 0:60a522ae2e35 | 62 |