Adafruit FeatherOLED example for the MAX32630FTHR board

Dependencies:   Adafruit_FeatherOLED USBDevice max32630fthr

Dependents:   Bracciale_master Bracciale_slave

Fork of FTHR_USB_serial by Maxim Integrated

Committer:
switches
Date:
Wed Feb 08 00:14:26 2017 +0000
Revision:
9:ecdad18f61c2
Parent:
8:1d48f139567d
Child:
10:1f5e78dd4a7c
Example program for Adafruit OLED Feather Wing with the MAX32630FTHR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 9:ecdad18f61c2 1 /**********************************************************************
switches 9:ecdad18f61c2 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
switches 9:ecdad18f61c2 3 *
switches 9:ecdad18f61c2 4 * Permission is hereby granted, free of charge, to any person obtaining a
switches 9:ecdad18f61c2 5 * copy of this software and associated documentation files (the "Software"),
switches 9:ecdad18f61c2 6 * to deal in the Software without restriction, including without limitation
switches 9:ecdad18f61c2 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
switches 9:ecdad18f61c2 8 * and/or sell copies of the Software, and to permit persons to whom the
switches 9:ecdad18f61c2 9 * Software is furnished to do so, subject to the following conditions:
switches 9:ecdad18f61c2 10 *
switches 9:ecdad18f61c2 11 * The above copyright notice and this permission notice shall be included
switches 9:ecdad18f61c2 12 * in all copies or substantial portions of the Software.
switches 9:ecdad18f61c2 13 *
switches 9:ecdad18f61c2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
switches 9:ecdad18f61c2 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
switches 9:ecdad18f61c2 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
switches 9:ecdad18f61c2 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
switches 9:ecdad18f61c2 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
switches 9:ecdad18f61c2 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
switches 9:ecdad18f61c2 20 * OTHER DEALINGS IN THE SOFTWARE.
switches 9:ecdad18f61c2 21 *
switches 9:ecdad18f61c2 22 * Except as contained in this notice, the name of Maxim Integrated
switches 9:ecdad18f61c2 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
switches 9:ecdad18f61c2 24 * Products, Inc. Branding Policy.
switches 9:ecdad18f61c2 25 *
switches 9:ecdad18f61c2 26 * The mere transfer of this software does not imply any licenses
switches 9:ecdad18f61c2 27 * of trade secrets, proprietary technology, copyrights, patents,
switches 9:ecdad18f61c2 28 * trademarks, maskwork rights, or any other form of intellectual
switches 9:ecdad18f61c2 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
switches 9:ecdad18f61c2 30 * ownership rights.
switches 9:ecdad18f61c2 31 **********************************************************************/
switches 9:ecdad18f61c2 32
switches 0:60a522ae2e35 33 #include "mbed.h"
switches 2:57500e991166 34 #include "max32630fthr.h"
switches 8:1d48f139567d 35 #include "Adafruit_SSD1306.h"
switches 1:6923b075c8d7 36 #include "USBSerial.h"
switches 0:60a522ae2e35 37
switches 6:684c51f32c1d 38 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
switches 0:60a522ae2e35 39
switches 8:1d48f139567d 40 I2C i2c(P3_4, P3_5); // SDA, SCL
switches 8:1d48f139567d 41
switches 9:ecdad18f61c2 42 Adafruit_SSD1306_I2c featherOLED(i2c); // I2C
switches 8:1d48f139567d 43
switches 1:6923b075c8d7 44 // Hardware serial port over DAPLink
switches 2:57500e991166 45 Serial daplink(P2_1, P2_0);
switches 1:6923b075c8d7 46
switches 3:601c11238ccb 47 // Virtual serial port over USB
switches 3:601c11238ccb 48 USBSerial microUSB;
switches 3:601c11238ccb 49
switches 2:57500e991166 50 DigitalOut rLED(LED1);
switches 2:57500e991166 51 DigitalOut gLED(LED2);
switches 2:57500e991166 52 DigitalOut bLED(LED3);
switches 0:60a522ae2e35 53
switches 9:ecdad18f61c2 54 DigitalIn aButton(P5_3, PullUp);
switches 9:ecdad18f61c2 55 DigitalIn bButton(P3_3, PullUp);
switches 9:ecdad18f61c2 56 DigitalIn cButton(P3_2, PullUp);
switches 9:ecdad18f61c2 57
switches 9:ecdad18f61c2 58 /* Analog inputs 0 and 1 have internal dividers to allow measuring 5V signals
switches 9:ecdad18f61c2 59 * The dividers are selected by using inputs AIN_5 and AIN_5 respectively.
switches 9:ecdad18f61c2 60 * The full scale range for AIN0-3 is 1.2V
switches 9:ecdad18f61c2 61 * The full scale range for AIN4-5 is 6.0V
switches 9:ecdad18f61c2 62 */
switches 9:ecdad18f61c2 63 AnalogIn ain0(AIN_4);
switches 9:ecdad18f61c2 64 AnalogIn ain1(AIN_5);
switches 9:ecdad18f61c2 65 AnalogIn ain2(AIN_2);
switches 8:1d48f139567d 66 AnalogIn ain3(AIN_3);
switches 8:1d48f139567d 67
switches 8:1d48f139567d 68
switches 0:60a522ae2e35 69 // main() runs in its own thread in the OS
switches 0:60a522ae2e35 70 // (note the calls to Thread::wait below for delays)
switches 0:60a522ae2e35 71 int main()
switches 0:60a522ae2e35 72 {
switches 1:6923b075c8d7 73 int c;
switches 8:1d48f139567d 74 c = ' ';
switches 2:57500e991166 75
switches 2:57500e991166 76 daplink.printf("daplink serial port\r\n");
switches 3:601c11238ccb 77 microUSB.printf("micro USB serial port\r\n");
switches 2:57500e991166 78 rLED = LED_ON;
switches 2:57500e991166 79 gLED = LED_ON;
switches 2:57500e991166 80 bLED = LED_OFF;
switches 0:60a522ae2e35 81
switches 8:1d48f139567d 82 featherOLED.printf("%ux%u OLED Display\r\n", featherOLED.width(), featherOLED.height());
switches 8:1d48f139567d 83 featherOLED.printf("HelloWorld \r");
switches 8:1d48f139567d 84 featherOLED.display();
switches 8:1d48f139567d 85
switches 2:57500e991166 86 rLED = LED_OFF;
switches 1:6923b075c8d7 87
switches 1:6923b075c8d7 88 while(1) {
switches 8:1d48f139567d 89 Thread::wait(250);
switches 8:1d48f139567d 90 if (microUSB.readable()) {
switches 8:1d48f139567d 91 c = microUSB.getc();
switches 8:1d48f139567d 92 microUSB.putc(c);
switches 8:1d48f139567d 93 daplink.putc(c);
switches 8:1d48f139567d 94 }
switches 8:1d48f139567d 95 if (daplink.readable()) {
switches 8:1d48f139567d 96 c = daplink.getc();
switches 8:1d48f139567d 97 microUSB.putc(c);
switches 8:1d48f139567d 98 daplink.putc(c);
switches 8:1d48f139567d 99 }
switches 9:ecdad18f61c2 100 rLED = aButton;
switches 9:ecdad18f61c2 101 gLED = bButton;
switches 9:ecdad18f61c2 102 bLED = cButton;
switches 8:1d48f139567d 103 featherOLED.clearDisplay();
switches 8:1d48f139567d 104 featherOLED.setTextCursor(0,0);
switches 8:1d48f139567d 105 featherOLED.printf("MAX32630FTHR OLED\n");
switches 9:ecdad18f61c2 106 featherOLED.printf("AIN0/1: %1.2f, %1.2f\n", (6.0f * ain0), (6.0f * ain1) ); // analog inputs 0,1
switches 9:ecdad18f61c2 107 featherOLED.printf("AIN2/3: %1.2f, %1.2f\n", (1.2f * ain2), (1.2f * ain3) ); // analog inputs 2,3
switches 9:ecdad18f61c2 108 featherOLED.printf("UART:%c A:%d B:%d C:%d\n", c, aButton.read(), bButton.read(), cButton.read()); // UART and Buttons
switches 8:1d48f139567d 109 featherOLED.display();
switches 8:1d48f139567d 110
switches 0:60a522ae2e35 111 }
switches 0:60a522ae2e35 112 }
switches 0:60a522ae2e35 113