Demo MAX7219 library on MIKROELEKTRONIKA Serial 7-Seg Display 8-Digit
Fork of MAX7219 by
Demo MAX7219 library on MIKROELEKTRONIKA Serial 7-Seg Display 8-Digit This demo has been tested on NUCLEO-F411RE
For 7 segments display : https://www.mikroe.com/serial-7-seg-8-digit-board
For MAX7219 https://www.maximintegrated.com/en/products/power/display-power-control/MAX7219.html
use library https://os.mbed.com/teams/Maxim-Integrated/code/MAX7219/
7 segments display is connected to default SPI on Arduino connectors. STM32 MISO on RC5_PB5 (MOSI) STM32 MOSI on MISO STM32 SCK on RC3_RF3 (SCK) STM32 SS on CS0 5v GND
see manual (https://download.mikroe.com/documents/add-on-boards/other/display/serial-7seg-8-digit-display/serial-7seg-8-digit-display-manual-v100.pdf ) and photo for details
max7219.h@5:d181c7532341, 2018-03-23 (annotated)
- Committer:
- cdupaty
- Date:
- Fri Mar 23 14:26:12 2018 +0000
- Revision:
- 5:d181c7532341
- Parent:
- 4:b5e4379a3d90
Demo MAX7219 library on MIKROELEKTRONIKA Serial 7-Seg Display 8-Digit; Update 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:798fb343e022 | 1 | /******************************************************************//** |
j3 | 0:798fb343e022 | 2 | * @file max7219.h |
j3 | 0:798fb343e022 | 3 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:798fb343e022 | 4 | * |
j3 | 0:798fb343e022 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:798fb343e022 | 6 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:798fb343e022 | 7 | * to deal in the Software without restriction, including without limitation |
j3 | 0:798fb343e022 | 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:798fb343e022 | 9 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:798fb343e022 | 10 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:798fb343e022 | 11 | * |
j3 | 0:798fb343e022 | 12 | * The above copyright notice and this permission notice shall be included |
j3 | 0:798fb343e022 | 13 | * in all copies or substantial portions of the Software. |
j3 | 0:798fb343e022 | 14 | * |
j3 | 0:798fb343e022 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:798fb343e022 | 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:798fb343e022 | 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:798fb343e022 | 18 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:798fb343e022 | 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:798fb343e022 | 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:798fb343e022 | 21 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:798fb343e022 | 22 | * |
j3 | 0:798fb343e022 | 23 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:798fb343e022 | 24 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:798fb343e022 | 25 | * Products, Inc. Branding Policy. |
j3 | 0:798fb343e022 | 26 | * |
j3 | 0:798fb343e022 | 27 | * The mere transfer of this software does not imply any licenses |
j3 | 0:798fb343e022 | 28 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:798fb343e022 | 29 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:798fb343e022 | 30 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:798fb343e022 | 31 | * ownership rights. |
j3 | 0:798fb343e022 | 32 | **********************************************************************/ |
j3 | 0:798fb343e022 | 33 | |
j3 | 0:798fb343e022 | 34 | |
j3 | 0:798fb343e022 | 35 | #ifndef MAX7219_H |
j3 | 0:798fb343e022 | 36 | #define MAX7219_H |
j3 | 0:798fb343e022 | 37 | |
j3 | 0:798fb343e022 | 38 | #include "mbed.h" |
j3 | 0:798fb343e022 | 39 | |
j3 | 0:798fb343e022 | 40 | |
j3 | 2:9150a0dc77a3 | 41 | /** |
j3 | 2:9150a0dc77a3 | 42 | * @brief Structure for device configuration |
j3 | 2:9150a0dc77a3 | 43 | * @code |
j3 | 2:9150a0dc77a3 | 44 | * #include "max7219.h" |
j3 | 2:9150a0dc77a3 | 45 | * |
j3 | 2:9150a0dc77a3 | 46 | * max7219_configuration_t cfg = { |
j3 | 2:9150a0dc77a3 | 47 | * .device_number = 1, |
j3 | 2:9150a0dc77a3 | 48 | * .decode_mode = 0, |
j3 | 2:9150a0dc77a3 | 49 | * .intensity = Max7219::MAX7219_INTENSITY_8, |
j3 | 2:9150a0dc77a3 | 50 | * .scan_limit = Max7219::MAX7219_SCAN_8 |
j3 | 2:9150a0dc77a3 | 51 | * }; |
j3 | 2:9150a0dc77a3 | 52 | * @endcode |
j3 | 2:9150a0dc77a3 | 53 | */ |
j3 | 0:798fb343e022 | 54 | typedef struct |
j3 | 0:798fb343e022 | 55 | { |
j3 | 0:798fb343e022 | 56 | uint8_t device_number; |
j3 | 0:798fb343e022 | 57 | uint8_t decode_mode; |
j3 | 0:798fb343e022 | 58 | uint8_t intensity; |
j3 | 0:798fb343e022 | 59 | uint8_t scan_limit; |
j3 | 0:798fb343e022 | 60 | }max7219_configuration_t; |
j3 | 0:798fb343e022 | 61 | |
j3 | 0:798fb343e022 | 62 | |
j3 | 2:9150a0dc77a3 | 63 | /** |
j3 | 2:9150a0dc77a3 | 64 | * @brief Serially Interfaced, 8-Digit, LED Display Driver |
j3 | 2:9150a0dc77a3 | 65 | * |
j3 | 2:9150a0dc77a3 | 66 | * @details The MAX7219/MAX7221 are compact, serial input/output common-cathode |
j3 | 2:9150a0dc77a3 | 67 | * display drivers that interface microprocessors (µPs) to 7-segment numeric |
j3 | 2:9150a0dc77a3 | 68 | * LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs. |
j3 | 2:9150a0dc77a3 | 69 | * Included on-chip are a BCD code-B decoder, multiplex scan circuitry, segment |
j3 | 2:9150a0dc77a3 | 70 | * and digit drivers, and an 8x8 static RAM that stores each digit. Only one |
j3 | 2:9150a0dc77a3 | 71 | * external resistor is required to set the segment current for all LEDs. |
j3 | 2:9150a0dc77a3 | 72 | * The MAX7221 is compatible with SPI™, QSPI™, and MICROWIRE™, and has |
j3 | 2:9150a0dc77a3 | 73 | * slew-rate-limited segment drivers to reduce EMI. |
j3 | 2:9150a0dc77a3 | 74 | * |
j3 | 2:9150a0dc77a3 | 75 | * @code |
j3 | 2:9150a0dc77a3 | 76 | * #include "mbed.h" |
j3 | 2:9150a0dc77a3 | 77 | * #include "max7219.h" |
j3 | 2:9150a0dc77a3 | 78 | * |
j3 | 2:9150a0dc77a3 | 79 | * Max7219 max7219(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS); |
j3 | 2:9150a0dc77a3 | 80 | * |
j3 | 2:9150a0dc77a3 | 81 | * int main() |
j3 | 2:9150a0dc77a3 | 82 | * { |
j3 | 2:9150a0dc77a3 | 83 | * max7219_configuration_t cfg = { |
j3 | 2:9150a0dc77a3 | 84 | * .device_number = 1, |
j3 | 2:9150a0dc77a3 | 85 | * .decode_mode = 0, |
j3 | 2:9150a0dc77a3 | 86 | * .intensity = Max7219::MAX7219_INTENSITY_8, |
j3 | 2:9150a0dc77a3 | 87 | * .scan_limit = Max7219::MAX7219_SCAN_8 |
j3 | 2:9150a0dc77a3 | 88 | * }; |
j3 | 2:9150a0dc77a3 | 89 | * |
j3 | 2:9150a0dc77a3 | 90 | * max7219.init_device(cfg); |
j3 | 2:9150a0dc77a3 | 91 | * max7219.enable_device(1); |
j3 | 2:9150a0dc77a3 | 92 | * max7219.set_display_test(); |
j3 | 2:9150a0dc77a3 | 93 | * wait(1); |
j3 | 2:9150a0dc77a3 | 94 | * max7219.clear_display_test(); |
j3 | 2:9150a0dc77a3 | 95 | * |
j3 | 2:9150a0dc77a3 | 96 | * while (1) { |
j3 | 2:9150a0dc77a3 | 97 | * max7219.write_digit(1, Max7219::MAX7219_DIGIT_0, ... |
j3 | 2:9150a0dc77a3 | 98 | * } |
j3 | 2:9150a0dc77a3 | 99 | * } |
j3 | 2:9150a0dc77a3 | 100 | * @endcode |
j3 | 2:9150a0dc77a3 | 101 | */ |
j3 | 0:798fb343e022 | 102 | class Max7219 |
j3 | 0:798fb343e022 | 103 | { |
j3 | 0:798fb343e022 | 104 | public: |
j3 | 0:798fb343e022 | 105 | |
j3 | 2:9150a0dc77a3 | 106 | /** |
j3 | 2:9150a0dc77a3 | 107 | * @brief Digit and Control Registers |
j3 | 2:9150a0dc77a3 | 108 | * @details The 14 addressable digit and control registers. |
j3 | 2:9150a0dc77a3 | 109 | */ |
j3 | 0:798fb343e022 | 110 | typedef enum |
j3 | 0:798fb343e022 | 111 | { |
j3 | 0:798fb343e022 | 112 | MAX7219_NO_OP = 0, |
j3 | 0:798fb343e022 | 113 | MAX7219_DIGIT_0, |
j3 | 0:798fb343e022 | 114 | MAX7219_DIGIT_1, |
j3 | 0:798fb343e022 | 115 | MAX7219_DIGIT_2, |
j3 | 0:798fb343e022 | 116 | MAX7219_DIGIT_3, |
j3 | 0:798fb343e022 | 117 | MAX7219_DIGIT_4, |
j3 | 0:798fb343e022 | 118 | MAX7219_DIGIT_5, |
j3 | 0:798fb343e022 | 119 | MAX7219_DIGIT_6, |
j3 | 0:798fb343e022 | 120 | MAX7219_DIGIT_7, |
j3 | 0:798fb343e022 | 121 | MAX7219_DECODE_MODE, |
j3 | 0:798fb343e022 | 122 | MAX7219_INTENSITY, |
j3 | 0:798fb343e022 | 123 | MAX7219_SCAN_LIMIT, |
j3 | 0:798fb343e022 | 124 | MAX7219_SHUTDOWN, |
j3 | 0:798fb343e022 | 125 | MAX7219_DISPLAY_TEST = 15 |
j3 | 0:798fb343e022 | 126 | }max7219_register_e; |
j3 | 0:798fb343e022 | 127 | |
j3 | 0:798fb343e022 | 128 | |
j3 | 2:9150a0dc77a3 | 129 | /** |
j3 | 2:9150a0dc77a3 | 130 | * @brief Intensity values |
j3 | 2:9150a0dc77a3 | 131 | * @details Digital control of display brightness is provided by an |
j3 | 2:9150a0dc77a3 | 132 | * internal pulse-width modulator, which is controlled by |
j3 | 2:9150a0dc77a3 | 133 | * the lower nibble of the intensity register. |
j3 | 2:9150a0dc77a3 | 134 | */ |
j3 | 0:798fb343e022 | 135 | typedef enum |
j3 | 0:798fb343e022 | 136 | { |
j3 | 0:798fb343e022 | 137 | MAX7219_INTENSITY_0 = 0, |
j3 | 0:798fb343e022 | 138 | MAX7219_INTENSITY_1, |
j3 | 0:798fb343e022 | 139 | MAX7219_INTENSITY_2, |
j3 | 0:798fb343e022 | 140 | MAX7219_INTENSITY_3, |
j3 | 0:798fb343e022 | 141 | MAX7219_INTENSITY_4, |
j3 | 0:798fb343e022 | 142 | MAX7219_INTENSITY_5, |
j3 | 0:798fb343e022 | 143 | MAX7219_INTENSITY_6, |
j3 | 0:798fb343e022 | 144 | MAX7219_INTENSITY_7, |
j3 | 0:798fb343e022 | 145 | MAX7219_INTENSITY_8, |
j3 | 0:798fb343e022 | 146 | MAX7219_INTENSITY_9, |
j3 | 0:798fb343e022 | 147 | MAX7219_INTENSITY_A, |
j3 | 0:798fb343e022 | 148 | MAX7219_INTENSITY_B, |
j3 | 0:798fb343e022 | 149 | MAX7219_INTENSITY_C, |
j3 | 0:798fb343e022 | 150 | MAX7219_INTENSITY_D, |
j3 | 0:798fb343e022 | 151 | MAX7219_INTENSITY_E, |
j3 | 0:798fb343e022 | 152 | MAX7219_INTENSITY_F |
j3 | 0:798fb343e022 | 153 | }max7219_intensity_e; |
j3 | 0:798fb343e022 | 154 | |
j3 | 0:798fb343e022 | 155 | |
j3 | 2:9150a0dc77a3 | 156 | /** |
j3 | 2:9150a0dc77a3 | 157 | * @brief Scan limit for mutiplexing digits |
j3 | 2:9150a0dc77a3 | 158 | * @details The scan-limit register sets how many digits are |
j3 | 2:9150a0dc77a3 | 159 | * displayed, from 1 to 8. They are displayed in a multiplexed |
j3 | 2:9150a0dc77a3 | 160 | * manner with a typical display scan rate of 800Hz with 8 |
j3 | 2:9150a0dc77a3 | 161 | * digits displayed. |
j3 | 2:9150a0dc77a3 | 162 | */ |
j3 | 0:798fb343e022 | 163 | typedef enum |
j3 | 0:798fb343e022 | 164 | { |
j3 | 0:798fb343e022 | 165 | MAX7219_SCAN_1 = 0, |
j3 | 0:798fb343e022 | 166 | MAX7219_SCAN_2, |
j3 | 0:798fb343e022 | 167 | MAX7219_SCAN_3, |
j3 | 0:798fb343e022 | 168 | MAX7219_SCAN_4, |
j3 | 0:798fb343e022 | 169 | MAX7219_SCAN_5, |
j3 | 0:798fb343e022 | 170 | MAX7219_SCAN_6, |
j3 | 0:798fb343e022 | 171 | MAX7219_SCAN_7, |
j3 | 0:798fb343e022 | 172 | MAX7219_SCAN_8 |
j3 | 0:798fb343e022 | 173 | }max7219_scan_limit_e; |
j3 | 0:798fb343e022 | 174 | |
j3 | 0:798fb343e022 | 175 | |
j3 | 0:798fb343e022 | 176 | /**********************************************************//** |
j3 | 0:798fb343e022 | 177 | * @brief Constructor for Max7219 Class. |
j3 | 0:798fb343e022 | 178 | * |
j3 | 0:798fb343e022 | 179 | * @details Allows user to pass pointer to existing SPI bus |
j3 | 0:798fb343e022 | 180 | * |
j3 | 0:798fb343e022 | 181 | * On Entry: |
j3 | 0:798fb343e022 | 182 | * @param[in] spi_bus - pointer to existing SPI object |
j3 | 0:798fb343e022 | 183 | * @param[in] cs - pin to use for cs |
j3 | 0:798fb343e022 | 184 | * |
j3 | 0:798fb343e022 | 185 | * On Exit: |
j3 | 4:b5e4379a3d90 | 186 | * |
j3 | 4:b5e4379a3d90 | 187 | * @return None |
j3 | 0:798fb343e022 | 188 | **************************************************************/ |
j3 | 0:798fb343e022 | 189 | Max7219(SPI *spi_bus, PinName cs); |
j3 | 0:798fb343e022 | 190 | |
j3 | 0:798fb343e022 | 191 | |
j3 | 0:798fb343e022 | 192 | /**********************************************************//** |
j3 | 0:798fb343e022 | 193 | * @brief Constructor for Max7219 Class. |
j3 | 0:798fb343e022 | 194 | * |
j3 | 0:798fb343e022 | 195 | * @details Allows user to specify SPI peripheral to use |
j3 | 0:798fb343e022 | 196 | * |
j3 | 0:798fb343e022 | 197 | * On Entry: |
j3 | 0:798fb343e022 | 198 | * @param[in] mosi - pin to use for mosi |
j3 | 0:798fb343e022 | 199 | * @param[in] miso - pin to use for miso |
j3 | 0:798fb343e022 | 200 | * @param[in] sclk - pin to use for sclk |
j3 | 0:798fb343e022 | 201 | * @param[in] cs - pin to use for cs |
j3 | 0:798fb343e022 | 202 | * |
j3 | 0:798fb343e022 | 203 | * On Exit: |
j3 | 4:b5e4379a3d90 | 204 | * |
j3 | 4:b5e4379a3d90 | 205 | * @return None |
j3 | 0:798fb343e022 | 206 | **************************************************************/ |
j3 | 0:798fb343e022 | 207 | Max7219(PinName mosi, PinName miso, PinName sclk, PinName cs); |
j3 | 0:798fb343e022 | 208 | |
j3 | 0:798fb343e022 | 209 | |
j3 | 0:798fb343e022 | 210 | /**********************************************************//** |
j3 | 0:798fb343e022 | 211 | * @brief Default destructor for Max7219 Class. |
j3 | 0:798fb343e022 | 212 | * |
j3 | 0:798fb343e022 | 213 | * @details Destroys SPI object if owner |
j3 | 0:798fb343e022 | 214 | * |
j3 | 0:798fb343e022 | 215 | * On Entry: |
j3 | 0:798fb343e022 | 216 | * |
j3 | 0:798fb343e022 | 217 | * On Exit: |
j3 | 4:b5e4379a3d90 | 218 | * |
j3 | 4:b5e4379a3d90 | 219 | * @return None |
j3 | 0:798fb343e022 | 220 | **************************************************************/ |
j3 | 0:798fb343e022 | 221 | ~Max7219(); |
j3 | 0:798fb343e022 | 222 | |
j3 | 0:798fb343e022 | 223 | |
j3 | 0:798fb343e022 | 224 | /**********************************************************//** |
j3 | 0:798fb343e022 | 225 | * @brief Sets the number of MAX7219 devices being used. |
j3 | 0:798fb343e022 | 226 | * Defaults to one |
j3 | 0:798fb343e022 | 227 | * |
j3 | 0:798fb343e022 | 228 | * @details |
j3 | 0:798fb343e022 | 229 | * |
j3 | 0:798fb343e022 | 230 | * On Entry: |
j3 | 0:798fb343e022 | 231 | * @param[in] num_devices - number of MAX7219 devices being |
j3 | 0:798fb343e022 | 232 | * used, max of 255 |
j3 | 0:798fb343e022 | 233 | * |
j3 | 0:798fb343e022 | 234 | * On Exit: |
j3 | 4:b5e4379a3d90 | 235 | * |
j3 | 4:b5e4379a3d90 | 236 | * @return Returns number of devices |
j3 | 0:798fb343e022 | 237 | **************************************************************/ |
j3 | 0:798fb343e022 | 238 | int32_t set_num_devices(uint8_t num_devices); |
j3 | 0:798fb343e022 | 239 | |
j3 | 0:798fb343e022 | 240 | |
j3 | 0:798fb343e022 | 241 | /**********************************************************//** |
j3 | 0:798fb343e022 | 242 | * @brief Tests all devices being used |
j3 | 0:798fb343e022 | 243 | * |
j3 | 0:798fb343e022 | 244 | * @details Sets bit0 of DISPLAY_TEST regiser in all devices |
j3 | 0:798fb343e022 | 245 | * |
j3 | 0:798fb343e022 | 246 | * On Entry: |
j3 | 0:798fb343e022 | 247 | * |
j3 | 0:798fb343e022 | 248 | * On Exit: |
j3 | 4:b5e4379a3d90 | 249 | * |
j3 | 4:b5e4379a3d90 | 250 | * @return None |
j3 | 0:798fb343e022 | 251 | **************************************************************/ |
j3 | 0:798fb343e022 | 252 | void set_display_test(void); |
j3 | 0:798fb343e022 | 253 | |
j3 | 0:798fb343e022 | 254 | |
j3 | 0:798fb343e022 | 255 | /**********************************************************//** |
j3 | 0:798fb343e022 | 256 | * @brief Stops test |
j3 | 0:798fb343e022 | 257 | * |
j3 | 0:798fb343e022 | 258 | * @details Clear bit0 of DISPLAY_TEST regiser in all devices |
j3 | 0:798fb343e022 | 259 | * |
j3 | 0:798fb343e022 | 260 | * On Entry: |
j3 | 0:798fb343e022 | 261 | * |
j3 | 0:798fb343e022 | 262 | * On Exit: |
j3 | 4:b5e4379a3d90 | 263 | * |
j3 | 4:b5e4379a3d90 | 264 | * @return None |
j3 | 0:798fb343e022 | 265 | **************************************************************/ |
j3 | 0:798fb343e022 | 266 | void clear_display_test(void); |
j3 | 0:798fb343e022 | 267 | |
j3 | 0:798fb343e022 | 268 | |
j3 | 0:798fb343e022 | 269 | /**********************************************************//** |
j3 | 3:c245060379b9 | 270 | * @brief Initializes specific device in display with given |
j3 | 0:798fb343e022 | 271 | * config data |
j3 | 0:798fb343e022 | 272 | * |
j3 | 0:798fb343e022 | 273 | * @details |
j3 | 0:798fb343e022 | 274 | * |
j3 | 0:798fb343e022 | 275 | * On Entry: |
j3 | 1:90a7cf4e7d26 | 276 | * @param[in] config - Structure containing configuration |
j3 | 1:90a7cf4e7d26 | 277 | * data of device |
j3 | 0:798fb343e022 | 278 | * |
j3 | 0:798fb343e022 | 279 | * On Exit: |
j3 | 4:b5e4379a3d90 | 280 | * |
j3 | 4:b5e4379a3d90 | 281 | * @return Returns 0 on success\n |
j3 | 4:b5e4379a3d90 | 282 | * Returns -1 if device number is > _num_devices\n |
j3 | 4:b5e4379a3d90 | 283 | * Returns -2 if device number is 0\n |
j3 | 0:798fb343e022 | 284 | **************************************************************/ |
j3 | 1:90a7cf4e7d26 | 285 | int32_t init_device(max7219_configuration_t config); |
j3 | 0:798fb343e022 | 286 | |
j3 | 0:798fb343e022 | 287 | |
j3 | 0:798fb343e022 | 288 | /**********************************************************//** |
j3 | 3:c245060379b9 | 289 | * @brief Initializes all devices with given config data |
j3 | 0:798fb343e022 | 290 | * |
j3 | 3:c245060379b9 | 291 | * @details All devices are configured with given data |
j3 | 0:798fb343e022 | 292 | * |
j3 | 0:798fb343e022 | 293 | * On Entry: |
j3 | 1:90a7cf4e7d26 | 294 | * @param[in] config - Structure containing configuration |
j3 | 1:90a7cf4e7d26 | 295 | * data |
j3 | 0:798fb343e022 | 296 | * On Exit: |
j3 | 4:b5e4379a3d90 | 297 | * |
j3 | 4:b5e4379a3d90 | 298 | * @return None |
j3 | 0:798fb343e022 | 299 | **************************************************************/ |
j3 | 0:798fb343e022 | 300 | void init_display(max7219_configuration_t config); |
j3 | 0:798fb343e022 | 301 | |
j3 | 0:798fb343e022 | 302 | |
j3 | 0:798fb343e022 | 303 | /**********************************************************//** |
j3 | 3:c245060379b9 | 304 | * @brief Enables specific device in display |
j3 | 0:798fb343e022 | 305 | * |
j3 | 0:798fb343e022 | 306 | * @details |
j3 | 0:798fb343e022 | 307 | * |
j3 | 0:798fb343e022 | 308 | * On Entry: |
j3 | 1:90a7cf4e7d26 | 309 | * @param[in] device_number - device to enable |
j3 | 0:798fb343e022 | 310 | * |
j3 | 0:798fb343e022 | 311 | * On Exit: |
j3 | 4:b5e4379a3d90 | 312 | * |
j3 | 4:b5e4379a3d90 | 313 | * @return Returns 0 on success\n |
j3 | 4:b5e4379a3d90 | 314 | * Returns -1 if device number is > _num_devices\n |
j3 | 4:b5e4379a3d90 | 315 | * Returns -2 if device number is 0\n |
j3 | 0:798fb343e022 | 316 | **************************************************************/ |
j3 | 0:798fb343e022 | 317 | int32_t enable_device(uint8_t device_number); |
j3 | 0:798fb343e022 | 318 | |
j3 | 0:798fb343e022 | 319 | |
j3 | 0:798fb343e022 | 320 | /**********************************************************//** |
j3 | 3:c245060379b9 | 321 | * @brief Enables all device in display |
j3 | 0:798fb343e022 | 322 | * |
j3 | 0:798fb343e022 | 323 | * @details |
j3 | 0:798fb343e022 | 324 | * |
j3 | 0:798fb343e022 | 325 | * On Entry: |
j3 | 0:798fb343e022 | 326 | * |
j3 | 0:798fb343e022 | 327 | * On Exit: |
j3 | 4:b5e4379a3d90 | 328 | * |
j3 | 4:b5e4379a3d90 | 329 | * @return None |
j3 | 0:798fb343e022 | 330 | **************************************************************/ |
j3 | 0:798fb343e022 | 331 | void enable_display(void); |
j3 | 0:798fb343e022 | 332 | |
j3 | 0:798fb343e022 | 333 | |
j3 | 0:798fb343e022 | 334 | /**********************************************************//** |
j3 | 3:c245060379b9 | 335 | * @brief Disables specific device in display |
j3 | 0:798fb343e022 | 336 | * |
j3 | 0:798fb343e022 | 337 | * @details |
j3 | 0:798fb343e022 | 338 | * |
j3 | 0:798fb343e022 | 339 | * On Entry: |
j3 | 1:90a7cf4e7d26 | 340 | * @param[in] device_number - device to disable |
j3 | 0:798fb343e022 | 341 | * |
j3 | 0:798fb343e022 | 342 | * On Exit: |
j3 | 4:b5e4379a3d90 | 343 | * @return Returns 0 on success\n |
j3 | 4:b5e4379a3d90 | 344 | * Returns -1 if device number is > _num_devices\n |
j3 | 4:b5e4379a3d90 | 345 | * Returns -2 if device number is 0\n |
j3 | 0:798fb343e022 | 346 | **************************************************************/ |
j3 | 0:798fb343e022 | 347 | int32_t disable_device(uint8_t device_number); |
j3 | 0:798fb343e022 | 348 | |
j3 | 0:798fb343e022 | 349 | |
j3 | 0:798fb343e022 | 350 | /**********************************************************//** |
j3 | 3:c245060379b9 | 351 | * @brief Disables all devices in display |
j3 | 0:798fb343e022 | 352 | * |
j3 | 0:798fb343e022 | 353 | * @details |
j3 | 0:798fb343e022 | 354 | * |
j3 | 0:798fb343e022 | 355 | * On Entry: |
j3 | 0:798fb343e022 | 356 | * |
j3 | 0:798fb343e022 | 357 | * On Exit: |
j3 | 4:b5e4379a3d90 | 358 | * |
j3 | 4:b5e4379a3d90 | 359 | * @return None |
j3 | 0:798fb343e022 | 360 | **************************************************************/ |
j3 | 0:798fb343e022 | 361 | void disable_display(void); |
j3 | 0:798fb343e022 | 362 | |
j3 | 0:798fb343e022 | 363 | |
j3 | 0:798fb343e022 | 364 | /**********************************************************//** |
j3 | 3:c245060379b9 | 365 | * @brief Writes digit of given device with given data, user |
j3 | 0:798fb343e022 | 366 | * must enter correct data for decode_mode chosen |
j3 | 0:798fb343e022 | 367 | * |
j3 | 0:798fb343e022 | 368 | * @details |
j3 | 0:798fb343e022 | 369 | * |
j3 | 0:798fb343e022 | 370 | * On Entry: |
j3 | 1:90a7cf4e7d26 | 371 | * @param[in] device_number - device to write too |
j3 | 1:90a7cf4e7d26 | 372 | * @param[in] digit - digit to write |
j3 | 1:90a7cf4e7d26 | 373 | * @param[in] data - data to write |
j3 | 0:798fb343e022 | 374 | * |
j3 | 0:798fb343e022 | 375 | * On Exit: |
j3 | 4:b5e4379a3d90 | 376 | * |
j3 | 4:b5e4379a3d90 | 377 | * @return Returns 0 on success\n |
j3 | 4:b5e4379a3d90 | 378 | * Returns -1 if device number is > _num_devices\n |
j3 | 4:b5e4379a3d90 | 379 | * Returns -2 if device number is 0\n |
j3 | 4:b5e4379a3d90 | 380 | * Returns -3 if digit > 8\n |
j3 | 4:b5e4379a3d90 | 381 | * Returns -4 if digit < 1\n |
j3 | 0:798fb343e022 | 382 | **************************************************************/ |
j3 | 0:798fb343e022 | 383 | int32_t write_digit(uint8_t device_number, uint8_t digit, uint8_t data); |
j3 | 0:798fb343e022 | 384 | |
j3 | 0:798fb343e022 | 385 | |
j3 | 0:798fb343e022 | 386 | /**********************************************************//** |
j3 | 3:c245060379b9 | 387 | * @brief Clears digit of given device |
j3 | 0:798fb343e022 | 388 | * |
j3 | 0:798fb343e022 | 389 | * @details |
j3 | 0:798fb343e022 | 390 | * |
j3 | 0:798fb343e022 | 391 | * On Entry: |
j3 | 1:90a7cf4e7d26 | 392 | * @param[in] device_number - device to write too |
j3 | 1:90a7cf4e7d26 | 393 | * @param[in] digit - digit to clear |
j3 | 0:798fb343e022 | 394 | * |
j3 | 0:798fb343e022 | 395 | * On Exit: |
j3 | 4:b5e4379a3d90 | 396 | * |
j3 | 4:b5e4379a3d90 | 397 | * @return Returns 0 on success\n |
j3 | 4:b5e4379a3d90 | 398 | * Returns -1 if device number is > _num_devices\n |
j3 | 4:b5e4379a3d90 | 399 | * Returns -2 if device number is 0\n |
j3 | 4:b5e4379a3d90 | 400 | * Returns -3 if digit > 8\n |
j3 | 4:b5e4379a3d90 | 401 | * Returns -4 if digit < 1\n |
j3 | 0:798fb343e022 | 402 | **************************************************************/ |
j3 | 0:798fb343e022 | 403 | int32_t clear_digit(uint8_t device_number, uint8_t digit); |
j3 | 0:798fb343e022 | 404 | |
j3 | 0:798fb343e022 | 405 | |
j3 | 0:798fb343e022 | 406 | /**********************************************************//** |
j3 | 3:c245060379b9 | 407 | * @brief Turns on all segments/digits of given device |
j3 | 0:798fb343e022 | 408 | * |
j3 | 0:798fb343e022 | 409 | * @details |
j3 | 0:798fb343e022 | 410 | * |
j3 | 0:798fb343e022 | 411 | * On Entry: |
j3 | 1:90a7cf4e7d26 | 412 | * @param[in] device_number - device to write too |
j3 | 0:798fb343e022 | 413 | * |
j3 | 0:798fb343e022 | 414 | * On Exit: |
j3 | 4:b5e4379a3d90 | 415 | * |
j3 | 4:b5e4379a3d90 | 416 | * @return Returns 0 on success\n |
j3 | 4:b5e4379a3d90 | 417 | * Returns -1 if device number is > _num_devices\n |
j3 | 4:b5e4379a3d90 | 418 | * Returns -2 if device number is 0\n |
j3 | 0:798fb343e022 | 419 | **************************************************************/ |
j3 | 0:798fb343e022 | 420 | int32_t device_all_on(uint8_t device_number); |
j3 | 0:798fb343e022 | 421 | |
j3 | 0:798fb343e022 | 422 | |
j3 | 0:798fb343e022 | 423 | /**********************************************************//** |
j3 | 3:c245060379b9 | 424 | * @brief Turns off all segments/digits of given device |
j3 | 0:798fb343e022 | 425 | * |
j3 | 0:798fb343e022 | 426 | * @details |
j3 | 0:798fb343e022 | 427 | * |
j3 | 0:798fb343e022 | 428 | * On Entry: |
j3 | 1:90a7cf4e7d26 | 429 | * @param[in] device_number - device to write too |
j3 | 0:798fb343e022 | 430 | * |
j3 | 0:798fb343e022 | 431 | * On Exit: |
j3 | 4:b5e4379a3d90 | 432 | * |
j3 | 4:b5e4379a3d90 | 433 | * @return Returns 0 on success\n |
j3 | 4:b5e4379a3d90 | 434 | * Returns -1 if device number is > _num_devices\n |
j3 | 4:b5e4379a3d90 | 435 | * Returns -2 if device number is 0\n |
j3 | 0:798fb343e022 | 436 | **************************************************************/ |
j3 | 0:798fb343e022 | 437 | int32_t device_all_off(uint8_t device_number); |
j3 | 0:798fb343e022 | 438 | |
j3 | 0:798fb343e022 | 439 | |
j3 | 0:798fb343e022 | 440 | /**********************************************************//** |
j3 | 3:c245060379b9 | 441 | * @brief Turns on all segments/digits of display |
j3 | 0:798fb343e022 | 442 | * |
j3 | 0:798fb343e022 | 443 | * @details |
j3 | 0:798fb343e022 | 444 | * |
j3 | 0:798fb343e022 | 445 | * On Entry: |
j3 | 0:798fb343e022 | 446 | * |
j3 | 0:798fb343e022 | 447 | * On Exit: |
j3 | 4:b5e4379a3d90 | 448 | * |
j3 | 4:b5e4379a3d90 | 449 | * @return None |
j3 | 0:798fb343e022 | 450 | **************************************************************/ |
j3 | 0:798fb343e022 | 451 | void display_all_on(void); |
j3 | 0:798fb343e022 | 452 | |
j3 | 0:798fb343e022 | 453 | |
j3 | 0:798fb343e022 | 454 | /**********************************************************//** |
j3 | 3:c245060379b9 | 455 | * @brief Turns off all segments/digits of display |
j3 | 0:798fb343e022 | 456 | * |
j3 | 0:798fb343e022 | 457 | * @details |
j3 | 0:798fb343e022 | 458 | * |
j3 | 0:798fb343e022 | 459 | * On Entry: |
j3 | 0:798fb343e022 | 460 | * |
j3 | 0:798fb343e022 | 461 | * On Exit: |
j3 | 4:b5e4379a3d90 | 462 | * |
j3 | 4:b5e4379a3d90 | 463 | * @return None |
j3 | 0:798fb343e022 | 464 | **************************************************************/ |
j3 | 0:798fb343e022 | 465 | void display_all_off(void); |
j3 | 0:798fb343e022 | 466 | |
j3 | 0:798fb343e022 | 467 | |
j3 | 0:798fb343e022 | 468 | private: |
j3 | 0:798fb343e022 | 469 | |
j3 | 0:798fb343e022 | 470 | SPI *_p_spi; |
j3 | 0:798fb343e022 | 471 | DigitalOut *_p_cs; |
j3 | 0:798fb343e022 | 472 | bool _spi_owner; |
j3 | 0:798fb343e022 | 473 | |
j3 | 0:798fb343e022 | 474 | uint8_t _num_devices; |
j3 | 0:798fb343e022 | 475 | |
j3 | 0:798fb343e022 | 476 | }; |
j3 | 0:798fb343e022 | 477 | #endif /* MAX7219_H*/ |