max32630fthr quad spi , unexpected spi behavior

Committer:
boonshen
Date:
Tue Mar 13 21:12:00 2018 +0000
Revision:
0:a35c40f49345
MAX32630FTHR QuadSPI test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
boonshen 0:a35c40f49345 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
boonshen 0:a35c40f49345 2 *
boonshen 0:a35c40f49345 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
boonshen 0:a35c40f49345 4 * and associated documentation files (the "Software"), to deal in the Software without
boonshen 0:a35c40f49345 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
boonshen 0:a35c40f49345 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
boonshen 0:a35c40f49345 7 * Software is furnished to do so, subject to the following conditions:
boonshen 0:a35c40f49345 8 *
boonshen 0:a35c40f49345 9 * The above copyright notice and this permission notice shall be included in all copies or
boonshen 0:a35c40f49345 10 * substantial portions of the Software.
boonshen 0:a35c40f49345 11 *
boonshen 0:a35c40f49345 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
boonshen 0:a35c40f49345 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
boonshen 0:a35c40f49345 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
boonshen 0:a35c40f49345 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
boonshen 0:a35c40f49345 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
boonshen 0:a35c40f49345 17 */
boonshen 0:a35c40f49345 18
boonshen 0:a35c40f49345 19 #ifndef USBKEYBOARD_H
boonshen 0:a35c40f49345 20 #define USBKEYBOARD_H
boonshen 0:a35c40f49345 21
boonshen 0:a35c40f49345 22 #include "USBHID.h"
boonshen 0:a35c40f49345 23 #include "Stream.h"
boonshen 0:a35c40f49345 24
boonshen 0:a35c40f49345 25 /* Modifiers */
boonshen 0:a35c40f49345 26 enum MODIFIER_KEY {
boonshen 0:a35c40f49345 27 KEY_CTRL = 1,
boonshen 0:a35c40f49345 28 KEY_SHIFT = 2,
boonshen 0:a35c40f49345 29 KEY_ALT = 4,
boonshen 0:a35c40f49345 30 };
boonshen 0:a35c40f49345 31
boonshen 0:a35c40f49345 32
boonshen 0:a35c40f49345 33 enum MEDIA_KEY {
boonshen 0:a35c40f49345 34 KEY_NEXT_TRACK, /*!< next Track Button */
boonshen 0:a35c40f49345 35 KEY_PREVIOUS_TRACK, /*!< Previous track Button */
boonshen 0:a35c40f49345 36 KEY_STOP, /*!< Stop Button */
boonshen 0:a35c40f49345 37 KEY_PLAY_PAUSE, /*!< Play/Pause Button */
boonshen 0:a35c40f49345 38 KEY_MUTE, /*!< Mute Button */
boonshen 0:a35c40f49345 39 KEY_VOLUME_UP, /*!< Volume Up Button */
boonshen 0:a35c40f49345 40 KEY_VOLUME_DOWN, /*!< Volume Down Button */
boonshen 0:a35c40f49345 41 };
boonshen 0:a35c40f49345 42
boonshen 0:a35c40f49345 43 enum FUNCTION_KEY {
boonshen 0:a35c40f49345 44 KEY_F1 = 128, /* F1 key */
boonshen 0:a35c40f49345 45 KEY_F2, /* F2 key */
boonshen 0:a35c40f49345 46 KEY_F3, /* F3 key */
boonshen 0:a35c40f49345 47 KEY_F4, /* F4 key */
boonshen 0:a35c40f49345 48 KEY_F5, /* F5 key */
boonshen 0:a35c40f49345 49 KEY_F6, /* F6 key */
boonshen 0:a35c40f49345 50 KEY_F7, /* F7 key */
boonshen 0:a35c40f49345 51 KEY_F8, /* F8 key */
boonshen 0:a35c40f49345 52 KEY_F9, /* F9 key */
boonshen 0:a35c40f49345 53 KEY_F10, /* F10 key */
boonshen 0:a35c40f49345 54 KEY_F11, /* F11 key */
boonshen 0:a35c40f49345 55 KEY_F12, /* F12 key */
boonshen 0:a35c40f49345 56
boonshen 0:a35c40f49345 57 KEY_PRINT_SCREEN, /* Print Screen key */
boonshen 0:a35c40f49345 58 KEY_SCROLL_LOCK, /* Scroll lock */
boonshen 0:a35c40f49345 59 KEY_CAPS_LOCK, /* caps lock */
boonshen 0:a35c40f49345 60 KEY_NUM_LOCK, /* num lock */
boonshen 0:a35c40f49345 61 KEY_INSERT, /* Insert key */
boonshen 0:a35c40f49345 62 KEY_HOME, /* Home key */
boonshen 0:a35c40f49345 63 KEY_PAGE_UP, /* Page Up key */
boonshen 0:a35c40f49345 64 KEY_PAGE_DOWN, /* Page Down key */
boonshen 0:a35c40f49345 65
boonshen 0:a35c40f49345 66 RIGHT_ARROW, /* Right arrow */
boonshen 0:a35c40f49345 67 LEFT_ARROW, /* Left arrow */
boonshen 0:a35c40f49345 68 DOWN_ARROW, /* Down arrow */
boonshen 0:a35c40f49345 69 UP_ARROW, /* Up arrow */
boonshen 0:a35c40f49345 70 };
boonshen 0:a35c40f49345 71
boonshen 0:a35c40f49345 72 /**
boonshen 0:a35c40f49345 73 * USBKeyboard example
boonshen 0:a35c40f49345 74 * @code
boonshen 0:a35c40f49345 75 *
boonshen 0:a35c40f49345 76 * #include "mbed.h"
boonshen 0:a35c40f49345 77 * #include "USBKeyboard.h"
boonshen 0:a35c40f49345 78 *
boonshen 0:a35c40f49345 79 * USBKeyboard key;
boonshen 0:a35c40f49345 80 *
boonshen 0:a35c40f49345 81 * int main(void)
boonshen 0:a35c40f49345 82 * {
boonshen 0:a35c40f49345 83 * while (1)
boonshen 0:a35c40f49345 84 * {
boonshen 0:a35c40f49345 85 * key.printf("Hello World\r\n");
boonshen 0:a35c40f49345 86 * wait(1);
boonshen 0:a35c40f49345 87 * }
boonshen 0:a35c40f49345 88 * }
boonshen 0:a35c40f49345 89 *
boonshen 0:a35c40f49345 90 * @endcode
boonshen 0:a35c40f49345 91 */
boonshen 0:a35c40f49345 92 class USBKeyboard: public USBHID, public Stream {
boonshen 0:a35c40f49345 93 public:
boonshen 0:a35c40f49345 94
boonshen 0:a35c40f49345 95 /**
boonshen 0:a35c40f49345 96 * Constructor
boonshen 0:a35c40f49345 97 *
boonshen 0:a35c40f49345 98 *
boonshen 0:a35c40f49345 99 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
boonshen 0:a35c40f49345 100 * @param vendor_id Your vendor_id (default: 0x1235)
boonshen 0:a35c40f49345 101 * @param product_id Your product_id (default: 0x0050)
boonshen 0:a35c40f49345 102 * @param product_release Your preoduct_release (default: 0x0001)
boonshen 0:a35c40f49345 103 *
boonshen 0:a35c40f49345 104 */
boonshen 0:a35c40f49345 105 USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001):
boonshen 0:a35c40f49345 106 USBHID(0, 0, vendor_id, product_id, product_release, false) {
boonshen 0:a35c40f49345 107 lock_status = 0;
boonshen 0:a35c40f49345 108 connect();
boonshen 0:a35c40f49345 109 };
boonshen 0:a35c40f49345 110
boonshen 0:a35c40f49345 111 /**
boonshen 0:a35c40f49345 112 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
boonshen 0:a35c40f49345 113 *
boonshen 0:a35c40f49345 114 * @code
boonshen 0:a35c40f49345 115 * //To send CTRL + s (save)
boonshen 0:a35c40f49345 116 * keyboard.keyCode('s', KEY_CTRL);
boonshen 0:a35c40f49345 117 * @endcode
boonshen 0:a35c40f49345 118 *
boonshen 0:a35c40f49345 119 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
boonshen 0:a35c40f49345 120 * @param key character to send
boonshen 0:a35c40f49345 121 * @returns true if there is no error, false otherwise
boonshen 0:a35c40f49345 122 */
boonshen 0:a35c40f49345 123 bool keyCode(uint8_t key, uint8_t modifier = 0);
boonshen 0:a35c40f49345 124
boonshen 0:a35c40f49345 125 /**
boonshen 0:a35c40f49345 126 * Send a character
boonshen 0:a35c40f49345 127 *
boonshen 0:a35c40f49345 128 * @param c character to be sent
boonshen 0:a35c40f49345 129 * @returns true if there is no error, false otherwise
boonshen 0:a35c40f49345 130 */
boonshen 0:a35c40f49345 131 virtual int _putc(int c);
boonshen 0:a35c40f49345 132
boonshen 0:a35c40f49345 133 /**
boonshen 0:a35c40f49345 134 * Control media keys
boonshen 0:a35c40f49345 135 *
boonshen 0:a35c40f49345 136 * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN)
boonshen 0:a35c40f49345 137 * @returns true if there is no error, false otherwise
boonshen 0:a35c40f49345 138 */
boonshen 0:a35c40f49345 139 bool mediaControl(MEDIA_KEY key);
boonshen 0:a35c40f49345 140
boonshen 0:a35c40f49345 141 /*
boonshen 0:a35c40f49345 142 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
boonshen 0:a35c40f49345 143 *
boonshen 0:a35c40f49345 144 * @returns pointer to the report descriptor
boonshen 0:a35c40f49345 145 */
boonshen 0:a35c40f49345 146 virtual uint8_t * reportDesc();
boonshen 0:a35c40f49345 147
boonshen 0:a35c40f49345 148 /*
boonshen 0:a35c40f49345 149 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
boonshen 0:a35c40f49345 150 *
boonshen 0:a35c40f49345 151 * @returns if handle by subclass, return true
boonshen 0:a35c40f49345 152 */
boonshen 0:a35c40f49345 153 virtual bool EPINT_OUT_callback();
boonshen 0:a35c40f49345 154
boonshen 0:a35c40f49345 155 /**
boonshen 0:a35c40f49345 156 * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important:
boonshen 0:a35c40f49345 157 * - First bit: NUM_LOCK
boonshen 0:a35c40f49345 158 * - Second bit: CAPS_LOCK
boonshen 0:a35c40f49345 159 * - Third bit: SCROLL_LOCK
boonshen 0:a35c40f49345 160 *
boonshen 0:a35c40f49345 161 * @returns status of lock keys
boonshen 0:a35c40f49345 162 */
boonshen 0:a35c40f49345 163 uint8_t lockStatus();
boonshen 0:a35c40f49345 164
boonshen 0:a35c40f49345 165 protected:
boonshen 0:a35c40f49345 166 /*
boonshen 0:a35c40f49345 167 * Get configuration descriptor
boonshen 0:a35c40f49345 168 *
boonshen 0:a35c40f49345 169 * @returns pointer to the configuration descriptor
boonshen 0:a35c40f49345 170 */
boonshen 0:a35c40f49345 171 virtual uint8_t * configurationDesc();
boonshen 0:a35c40f49345 172
boonshen 0:a35c40f49345 173 private:
boonshen 0:a35c40f49345 174 //dummy otherwise it doesn,t compile (we must define all methods of an abstract class)
boonshen 0:a35c40f49345 175 virtual int _getc() {
boonshen 0:a35c40f49345 176 return -1;
boonshen 0:a35c40f49345 177 };
boonshen 0:a35c40f49345 178
boonshen 0:a35c40f49345 179 uint8_t lock_status;
boonshen 0:a35c40f49345 180
boonshen 0:a35c40f49345 181 };
boonshen 0:a35c40f49345 182
boonshen 0:a35c40f49345 183 #endif