Hello World example for using the max14724 library
Dependencies: ard2pmod max14724 mbed
This is untested.
main.cpp@0:080c891e3e3a, 2015-04-27 (annotated)
- Committer:
- wt8008
- Date:
- Mon Apr 27 17:38:32 2015 +0000
- Revision:
- 0:080c891e3e3a
Initial Import
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wt8008 | 0:080c891e3e3a | 1 | /*********************************************************************** |
wt8008 | 0:080c891e3e3a | 2 | * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. |
wt8008 | 0:080c891e3e3a | 3 | * |
wt8008 | 0:080c891e3e3a | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
wt8008 | 0:080c891e3e3a | 5 | * copy of this software and associated documentation files (the "Software"), |
wt8008 | 0:080c891e3e3a | 6 | * to deal in the Software without restriction, including without limitation |
wt8008 | 0:080c891e3e3a | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
wt8008 | 0:080c891e3e3a | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
wt8008 | 0:080c891e3e3a | 9 | * Software is furnished to do so, subject to the following conditions: |
wt8008 | 0:080c891e3e3a | 10 | * |
wt8008 | 0:080c891e3e3a | 11 | * The above copyright notice and this permission notice shall be included |
wt8008 | 0:080c891e3e3a | 12 | * in all copies or substantial portions of the Software. |
wt8008 | 0:080c891e3e3a | 13 | * |
wt8008 | 0:080c891e3e3a | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
wt8008 | 0:080c891e3e3a | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
wt8008 | 0:080c891e3e3a | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
wt8008 | 0:080c891e3e3a | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
wt8008 | 0:080c891e3e3a | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
wt8008 | 0:080c891e3e3a | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
wt8008 | 0:080c891e3e3a | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
wt8008 | 0:080c891e3e3a | 21 | * |
wt8008 | 0:080c891e3e3a | 22 | * Except as contained in this notice, the name of Maxim Integrated |
wt8008 | 0:080c891e3e3a | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
wt8008 | 0:080c891e3e3a | 24 | * Products, Inc. Branding Policy. |
wt8008 | 0:080c891e3e3a | 25 | * |
wt8008 | 0:080c891e3e3a | 26 | * The mere transfer of this software does not imply any licenses |
wt8008 | 0:080c891e3e3a | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
wt8008 | 0:080c891e3e3a | 28 | * trademarks, maskwork rights, or any other form of intellectual |
wt8008 | 0:080c891e3e3a | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
wt8008 | 0:080c891e3e3a | 30 | * ownership rights. |
wt8008 | 0:080c891e3e3a | 31 | **********************************************************************/ |
wt8008 | 0:080c891e3e3a | 32 | |
wt8008 | 0:080c891e3e3a | 33 | // Tested with FRDM-K64F |
wt8008 | 0:080c891e3e3a | 34 | #include "mbed.h" |
wt8008 | 0:080c891e3e3a | 35 | |
wt8008 | 0:080c891e3e3a | 36 | #include "max14724.h" |
wt8008 | 0:080c891e3e3a | 37 | #include "ard2pmod.h" |
wt8008 | 0:080c891e3e3a | 38 | |
wt8008 | 0:080c891e3e3a | 39 | int main() { |
wt8008 | 0:080c891e3e3a | 40 | |
wt8008 | 0:080c891e3e3a | 41 | uint8_t data[4]; |
wt8008 | 0:080c891e3e3a | 42 | |
wt8008 | 0:080c891e3e3a | 43 | Serial pc(USBTX, USBRX); |
wt8008 | 0:080c891e3e3a | 44 | pc.printf("\r\n\r\nMAX14724 Hello World!\r\n"); |
wt8008 | 0:080c891e3e3a | 45 | |
wt8008 | 0:080c891e3e3a | 46 | Ard2Pmod a2p(Ard2Pmod::PMOD_TYPE_1_GPIO); // Configure ard2pmod multiplexer for GPIO (all switches open) |
wt8008 | 0:080c891e3e3a | 47 | a2p.set_switches((Ard2Pmod::SW11 | Ard2Pmod::SW09), (Ard2Pmod::SW13 | Ard2Pmod::SW10)); // Manually configure mux for custom I2C mapping |
wt8008 | 0:080c891e3e3a | 48 | a2p.rd_dir_registers(data); // Verify Ard2Pmod configuration with sucessful I2C read. |
wt8008 | 0:080c891e3e3a | 49 | pc.printf("Ad2Pmd mux data: 0x%02X 0x%02X 0x%02X 0x%02X\r\n", data[0], data[1], data[2], data[3]); |
wt8008 | 0:080c891e3e3a | 50 | |
wt8008 | 0:080c891e3e3a | 51 | Max14724 max14724(ARD2PMOD_SDA, ARD2PMOD_SCL, Max14724::MAX14724_I2C_ADRS1); |
wt8008 | 0:080c891e3e3a | 52 | |
wt8008 | 0:080c891e3e3a | 53 | //wait(2); // turn on delay |
wt8008 | 0:080c891e3e3a | 54 | |
wt8008 | 0:080c891e3e3a | 55 | // Write MAX14724 Switches Indirectly |
wt8008 | 0:080c891e3e3a | 56 | max14724.rd_dir_registers(data); |
wt8008 | 0:080c891e3e3a | 57 | pc.printf("DIR Registers: 0x%02X 0x%02X 0x%02X 0x%02X\r\n", data[0], data[1], data[2], data[3]); |
wt8008 | 0:080c891e3e3a | 58 | |
wt8008 | 0:080c891e3e3a | 59 | max14724.wrt_shadow_registers(Max14724::SW01, Max14724::SW02, Max14724::SW03, Max14724::SW04); |
wt8008 | 0:080c891e3e3a | 60 | pc.printf("Write Shadow Registers\r\n"); |
wt8008 | 0:080c891e3e3a | 61 | |
wt8008 | 0:080c891e3e3a | 62 | max14724.rd_dir_registers(data); |
wt8008 | 0:080c891e3e3a | 63 | pc.printf("DIR Registers: 0x%02X 0x%02X 0x%02X 0x%02X\r\n", data[0], data[1], data[2], data[3]); |
wt8008 | 0:080c891e3e3a | 64 | |
wt8008 | 0:080c891e3e3a | 65 | max14724.rd_shadow_registers(data); |
wt8008 | 0:080c891e3e3a | 66 | pc.printf("Shadow Registers: 0x%02X 0x%02X 0x%02X 0x%02X\r\n", data[0], data[1], data[2], data[3]); |
wt8008 | 0:080c891e3e3a | 67 | |
wt8008 | 0:080c891e3e3a | 68 | max14724.wrt_cmd_registers(Max14724::COPY_SHADOW, Max14724::COPY_SHADOW, Max14724::COPY_SHADOW, Max14724::COPY_SHADOW); |
wt8008 | 0:080c891e3e3a | 69 | pc.printf("Write Command Registers\r\n"); |
wt8008 | 0:080c891e3e3a | 70 | |
wt8008 | 0:080c891e3e3a | 71 | max14724.rd_dir_registers(data); |
wt8008 | 0:080c891e3e3a | 72 | pc.printf("DIR Registers: 0x%02X 0x%02X 0x%02X 0x%02X\r\n", data[0], data[1], data[2], data[3]); |
wt8008 | 0:080c891e3e3a | 73 | |
wt8008 | 0:080c891e3e3a | 74 | max14724.rd_shadow_registers(data); |
wt8008 | 0:080c891e3e3a | 75 | pc.printf("Shadow Registers: 0x%02X 0x%02X 0x%02X 0x%02X\r\n", data[0], data[1], data[2], data[3]); |
wt8008 | 0:080c891e3e3a | 76 | |
wt8008 | 0:080c891e3e3a | 77 | // Write MAX14724 Switches Directly |
wt8008 | 0:080c891e3e3a | 78 | max14724.set_switches(Max14724::SW05, Max14724::SW06, Max14724::SW07, Max14724::SW08); |
wt8008 | 0:080c891e3e3a | 79 | pc.printf("Set Switches Directly\r\n"); |
wt8008 | 0:080c891e3e3a | 80 | |
wt8008 | 0:080c891e3e3a | 81 | max14724.rd_dir_registers(data); |
wt8008 | 0:080c891e3e3a | 82 | pc.printf("DIR Registers: 0x%02X 0x%02X 0x%02X 0x%02X\r\n", data[0], data[1], data[2], data[3]); |
wt8008 | 0:080c891e3e3a | 83 | |
wt8008 | 0:080c891e3e3a | 84 | max14724.rd_shadow_registers(data); |
wt8008 | 0:080c891e3e3a | 85 | pc.printf("Shadow Registers: 0x%02X 0x%02X 0x%02X 0x%02X\r\n", data[0], data[1], data[2], data[3]); |
wt8008 | 0:080c891e3e3a | 86 | |
wt8008 | 0:080c891e3e3a | 87 | return 0; |
wt8008 | 0:080c891e3e3a | 88 | } |