diff options
Diffstat (limited to 'lib/chibios-contrib/os/various/devices_lib/others/max7219.c')
-rw-r--r-- | lib/chibios-contrib/os/various/devices_lib/others/max7219.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/various/devices_lib/others/max7219.c b/lib/chibios-contrib/os/various/devices_lib/others/max7219.c new file mode 100644 index 000000000..0e511671c --- /dev/null +++ b/lib/chibios-contrib/os/various/devices_lib/others/max7219.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | Pretty LAYer for ChibiOS/RT - Copyright (C) 2015 Rocco Marco Guglielmi | ||
3 | |||
4 | This file is part of PLAY for ChibiOS/RT. | ||
5 | |||
6 | PLAY is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 3 of the License, or | ||
9 | (at your option) any later version. | ||
10 | |||
11 | PLAY is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | /* | ||
21 | Special thanks to Giovanni Di Sirio for teachings, his moral support and | ||
22 | friendship. Note that some or every piece of this file could be part of | ||
23 | the ChibiOS project that is intellectual property of Giovanni Di Sirio. | ||
24 | Please refer to ChibiOS/RT license before use this file. | ||
25 | |||
26 | For suggestion or Bug report - [email protected] | ||
27 | */ | ||
28 | |||
29 | /** | ||
30 | * @file max7219.c | ||
31 | * @brief MAX7219 display driver module code. | ||
32 | * | ||
33 | * @addtogroup max7219 | ||
34 | * @{ | ||
35 | */ | ||
36 | |||
37 | #include "ch.h" | ||
38 | #include "hal.h" | ||
39 | |||
40 | #include "max7219.h" | ||
41 | |||
42 | /*===========================================================================*/ | ||
43 | /* Driver local definitions. */ | ||
44 | /*===========================================================================*/ | ||
45 | |||
46 | /*===========================================================================*/ | ||
47 | /* Driver exported variables. */ | ||
48 | /*===========================================================================*/ | ||
49 | |||
50 | /*===========================================================================*/ | ||
51 | /* Driver local variables and types. */ | ||
52 | /*===========================================================================*/ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Driver local functions. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | /*===========================================================================*/ | ||
59 | /* Driver exported functions. */ | ||
60 | /*===========================================================================*/ | ||
61 | |||
62 | /** | ||
63 | * @brief Reads a generic register value. | ||
64 | * @pre The SPI interface must be initialized and the driver started. | ||
65 | * | ||
66 | * @param[in] spip pointer to the SPI interface | ||
67 | * @param[in] adr address number | ||
68 | * @param[in] data data value. | ||
69 | */ | ||
70 | void max7219WriteRegister(SPIDriver *spip, uint16_t adr, uint8_t data) { | ||
71 | |||
72 | switch (adr) { | ||
73 | default: | ||
74 | return; | ||
75 | case MAX7219_AD_DIGIT_0: | ||
76 | case MAX7219_AD_DIGIT_1: | ||
77 | case MAX7219_AD_DIGIT_2: | ||
78 | case MAX7219_AD_DIGIT_3: | ||
79 | case MAX7219_AD_DIGIT_4: | ||
80 | case MAX7219_AD_DIGIT_5: | ||
81 | case MAX7219_AD_DIGIT_6: | ||
82 | case MAX7219_AD_DIGIT_7: | ||
83 | case MAX7219_AD_DECODE_MODE: | ||
84 | case MAX7219_AD_INTENSITY: | ||
85 | case MAX7219_AD_SCAN_LIMIT: | ||
86 | case MAX7219_AD_SHUTDOWN: | ||
87 | case MAX7219_AD_DISPLAY_TEST: | ||
88 | spiSelect(spip); | ||
89 | uint16_t txbuf = {adr | data}; | ||
90 | spiSend(spip, 1, &txbuf); | ||
91 | spiUnselect(spip); | ||
92 | } | ||
93 | } | ||
94 | /** @} */ | ||