add default settings, fix alphabet, fix order
This commit is contained in:
parent
ea2a56f578
commit
858a32be93
|
@ -17,15 +17,14 @@
|
|||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||
* @date 2017
|
||||
* @note peripherals used: GPIO @ref led_max7219_gpio, timer @ref led_tm1637_timer
|
||||
* @note the protocol is very similar to I2C but incompatible for the following reasons: the capacitance is too large for open-drain type output with weak pull-up resistors (push-pull needs to be used, preventing to get ACKs since no indication of the ACK timing is provided); the devices doesn't use addresses; the STM32 I2C will switch to receiver mode when the first sent byte (the I2C address) has last bit set to 1 (such as for address commands with B7=1 where B7 is transmitted last), preventing to send further bytes (the data byte after the address)
|
||||
* @warning all calls are blocking
|
||||
*
|
||||
* bit vs segment: 0bpgfedcba
|
||||
* bit vs segment: 0bpabcdefg
|
||||
* +a+
|
||||
* f b p
|
||||
* f b
|
||||
* +g+
|
||||
* e c p
|
||||
* +b+
|
||||
* +d+
|
||||
*/
|
||||
|
||||
/* standard libraries */
|
||||
|
@ -60,102 +59,114 @@
|
|||
* @note starts with space
|
||||
*/
|
||||
static const uint8_t ascii_7segments[] = {
|
||||
0x00, // 0b00000000 space
|
||||
0x30, // 0b00110000 ! (I)
|
||||
0x22, // 0b00100010 "
|
||||
0x5c, // 0b01011100 # (o)
|
||||
0x6d, // 0b01101101 $ (s)
|
||||
0x52, // 0b01010010 % (/)
|
||||
0x7d, // 0b01111101 & (6)
|
||||
0x20, // 0b00100000 '
|
||||
0x39, // 0b00111001 ( ([)
|
||||
0x0f, // 0b00001111 )
|
||||
0x70, // 0b01110000 *
|
||||
0x46, // 0b01000110 +
|
||||
0x10, // 0b00010000 ,
|
||||
0x40, // 0b01000000 -
|
||||
0x10, // 0b00010000 . (,)
|
||||
0x52, // 0b01010010 /
|
||||
0x3f, // 0b00111111 0
|
||||
0x06, // 0b00000110 1
|
||||
0x5b, // 0b01011011 2
|
||||
0x4f, // 0b01001111 3
|
||||
0x66, // 0b01100110 4
|
||||
0x6d, // 0b01101101 5
|
||||
0x7d, // 0b01111101 6
|
||||
0x07, // 0b00000111 7
|
||||
0x7f, // 0b01111111 8
|
||||
0x6f, // 0b01101111 9
|
||||
0x48, // 0b01001000 : (=)
|
||||
0x48, // 0b01001000 ; (=)
|
||||
0x58, // 0b01011000 <
|
||||
0x48, // 0b01001000 =
|
||||
0x4c, // 0b01001100 >
|
||||
0x53, // 0b01010011 ?
|
||||
0x7b, // 0b01111011 @
|
||||
0x77, // 0b01110111 A
|
||||
0x7f, // 0b01111111 B
|
||||
0x39, // 0b00111001 C
|
||||
0x5e, // 0b01011110 D
|
||||
0x79, // 0b01111001 E
|
||||
0x71, // 0b01110001 F
|
||||
0x3d, // 0b00111101 G
|
||||
0x76, // 0b01110110 H
|
||||
0x30, // 0b00110000 I
|
||||
0x1e, // 0b00011110 J
|
||||
0x76, // 0b01110110 K
|
||||
0x38, // 0b00111000 L
|
||||
0x37, // 0b00110111 M
|
||||
0x37, // 0b00110111 N
|
||||
0x3f, // 0b00111111 O
|
||||
0x73, // 0b01110011 P
|
||||
0x6b, // 0b01101011 Q
|
||||
0x33, // 0b00110011 R
|
||||
0x6d, // 0b01101101 S
|
||||
0x78, // 0b01111000 T
|
||||
0x3e, // 0b00111110 U
|
||||
0x3e, // 0b00111110 V (U)
|
||||
0x3e, // 0b00111110 W (U)
|
||||
0x76, // 0b01110110 X (H)
|
||||
0x6e, // 0b01101110 Y
|
||||
0x5b, // 0b01011011 Z
|
||||
0x39, // 0b00111001 [
|
||||
0x64, // 0b01100100 '\'
|
||||
0x0f, // 0b00001111 /
|
||||
0x23, // 0b00100011 ^
|
||||
0x08, // 0b00001000 _
|
||||
0x02, // 0b00000010 `
|
||||
0x5f, // 0b01011111 a
|
||||
0x7c, // 0b01111100 b
|
||||
0x58, // 0b01011000 c
|
||||
0x5e, // 0b01011110 d
|
||||
0x7b, // 0b01111011 e
|
||||
0x71, // 0b01110001 f
|
||||
0x6f, // 0b01101111 g
|
||||
0x74, // 0b01110100 h
|
||||
0x10, // 0b00010000 i
|
||||
0x0c, // 0b00001100 j
|
||||
0x76, // 0b01110110 k
|
||||
0x30, // 0b00110000 l
|
||||
0x54, // 0b01010100 m
|
||||
0x54, // 0b01010100 n
|
||||
0x5c, // 0b01011100 o
|
||||
0x73, // 0b01110011 p
|
||||
0x67, // 0b01100111 q
|
||||
0x50, // 0b01010000 r
|
||||
0x6d, // 0b01101101 s
|
||||
0x78, // 0b01111000 t
|
||||
0x1c, // 0b00011100 u
|
||||
0x1c, // 0b00011100 v (u)
|
||||
0x1c, // 0b00011100 w (u)
|
||||
0x76, // 0b01110110 x
|
||||
0x6e, // 0b01101110 y
|
||||
0x5b, // 0b01011011 z
|
||||
0x39, // 0b00111001 { ([)
|
||||
0x30, // 0b00110000 |
|
||||
0x0f, // 0b00001111 } ([)
|
||||
0x40, // 0b01000000 ~
|
||||
0x00, // space
|
||||
0x06, // ! (I)
|
||||
0x22, // "
|
||||
0x1d, // # (o)
|
||||
0x5b, // $ (s)
|
||||
0x25, // % (/)
|
||||
0x5f, // & (6)
|
||||
0x02, // '
|
||||
0x4e, // ( ([)
|
||||
0x78, // )
|
||||
0x07, // *
|
||||
0x31, // +
|
||||
0x04, // ,
|
||||
0x01, // -
|
||||
0x04, // . (,)
|
||||
0x25, // /
|
||||
0x7e, // 0
|
||||
0x30, // 1
|
||||
0x6d, // 2
|
||||
0x79, // 3
|
||||
0x33, // 4
|
||||
0x5b, // 5
|
||||
0x5f, // 6
|
||||
0x70, // 7
|
||||
0x7f, // 8
|
||||
0x7b, // 9
|
||||
0x09, // : (=)
|
||||
0x09, // ; (=)
|
||||
0x0d, // <
|
||||
0x09, // =
|
||||
0x19, // >
|
||||
0x65, // ?
|
||||
0x6f, // @
|
||||
0x77, // A
|
||||
0x7f, // B
|
||||
0x4e, // C
|
||||
0x3d, // D
|
||||
0x4f, // E
|
||||
0x47, // F
|
||||
0x5e, // G
|
||||
0x37, // H
|
||||
0x06, // I
|
||||
0x3c, // J
|
||||
0x37, // K
|
||||
0x0e, // L
|
||||
0x76, // M
|
||||
0x76, // N
|
||||
0x7e, // O
|
||||
0x67, // P
|
||||
0x6b, // Q
|
||||
0x66, // R
|
||||
0x5b, // S
|
||||
0x0f, // T
|
||||
0x3e, // U
|
||||
0x3e, // V (U)
|
||||
0x3e, // W (U)
|
||||
0x37, // X (H)
|
||||
0x3b, // Y
|
||||
0x6d, // Z
|
||||
0x4e, // [
|
||||
0x13, // '\'
|
||||
0x78, // /
|
||||
0x62, // ^
|
||||
0x08, // _
|
||||
0x20, // `
|
||||
0x7d, // a
|
||||
0x1f, // b
|
||||
0x0d, // c
|
||||
0x3d, // d
|
||||
0x6f, // e
|
||||
0x47, // f
|
||||
0x7b, // g
|
||||
0x17, // h
|
||||
0x04, // i
|
||||
0x18, // j
|
||||
0x37, // k
|
||||
0x06, // l
|
||||
0x15, // m
|
||||
0x15, // n
|
||||
0x1d, // o
|
||||
0x67, // p
|
||||
0x73, // q
|
||||
0x05, // r
|
||||
0x5b, // s
|
||||
0x0f, // t
|
||||
0x1c, // u
|
||||
0x1c, // v (u)
|
||||
0x1c, // w (u)
|
||||
0x37, // x
|
||||
0x3b, // y
|
||||
0x6d, // z
|
||||
0x4e, // { ([)
|
||||
0x06, // |
|
||||
0x78, // } ([)
|
||||
0x01, // ~
|
||||
};
|
||||
/** write data on SPI bus and handle load signal
|
||||
* @param[in] data bytes to write
|
||||
*/
|
||||
static void led_max7219_write(uint16_t data)
|
||||
{
|
||||
gpio_clear(GPIO(LED_MAX7219_LOAD_PORT), GPIO(LED_MAX7219_LOAD_PIN)); // ensure load pin is low (data is put in MAX7219 register on rising edge)
|
||||
while (SPI_SR(SPI(LED_MAX7219_SPI))&SPI_SR_BSY); // wait until not busy
|
||||
spi_send(SPI(LED_MAX7219_SPI), data); // send data
|
||||
while (!(SPI_SR(SPI(LED_MAX7219_SPI))&SPI_SR_TXE)); // wait until Tx is empty (reference manual says BSY should also cover this, but it doesn't)
|
||||
while (SPI_SR(SPI(LED_MAX7219_SPI))&SPI_SR_BSY); // wait until not busy (= transmission completed)
|
||||
gpio_set(GPIO(LED_MAX7219_LOAD_PORT), GPIO(LED_MAX7219_LOAD_PIN)); // create rising edge on load pin for data to be set in MAX7219 register
|
||||
}
|
||||
|
||||
void led_max7219_setup(void)
|
||||
{
|
||||
|
@ -174,30 +185,18 @@ void led_max7219_setup(void)
|
|||
spi_reset(SPI(LED_MAX7219_SPI)); // clear SPI values to default
|
||||
spi_init_master(SPI(LED_MAX7219_SPI), SPI_CR1_BAUDRATE_FPCLK_DIV_16, SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE, SPI_CR1_CPHA_CLK_TRANSITION_1, SPI_CR1_DFF_16BIT, SPI_CR1_MSBFIRST); // initialise SPI as master, divide clock by 8 since max MAX7219 clock is 10 MHz and max SPI PCLK clock is 72 Mhz, depending on which SPI is used, set clock polarity to idle high (polarity is not really important for the MAX7219), set clock phase to go high when bit is set (depends on polarity) as data is stored on MAX7219 on rising edge), use 16 bits frames (as used by MAX7219), use MSB first
|
||||
spi_set_unidirectional_mode(SPI(LED_MAX7219_SPI)); // we only need to transmit data
|
||||
//spi_enable_ss_output(SPI(LED_MAX7219_SPI)); // use NSS for LOAD line
|
||||
//spi_enable_software_slave_management(SPI(LED_MAX7219_SPI)); // control the slave select in software (since there is chip select)
|
||||
//spi_set_nss_low(SPI(LED_MAX7219_SPI)); // set NSS low so we can output
|
||||
spi_enable(SPI(LED_MAX7219_SPI)); // enable SPI
|
||||
}
|
||||
spi_enable(SPI(LED_MAX7219_SPI)); // enable SPI
|
||||
|
||||
/** write data on bus
|
||||
* @param[in] data bytes to write
|
||||
*/
|
||||
static void led_max7219_write(uint16_t data)
|
||||
{
|
||||
gpio_clear(GPIO(LED_MAX7219_LOAD_PORT), GPIO(LED_MAX7219_LOAD_PIN)); // ensure load pin is low (data is put in MAX7219 register on rising edge)
|
||||
spi_set_nss_low(SPI(LED_MAX7219_SPI));
|
||||
while (SPI_SR(SPI(LED_MAX7219_SPI))&SPI_SR_BSY); // wait until not busy
|
||||
spi_send(SPI(LED_MAX7219_SPI), data); // send data
|
||||
while (!(SPI_SR(SPI(LED_MAX7219_SPI))&SPI_SR_TXE)); // wait until Tx is empty (reference manual says BSY should also cover this, but it doesn't)
|
||||
while (SPI_SR(SPI(LED_MAX7219_SPI))&SPI_SR_BSY); // wait until not busy (= transmission completed)
|
||||
gpio_set(GPIO(LED_MAX7219_LOAD_PORT), GPIO(LED_MAX7219_LOAD_PIN)); // create rising edge on load pin for data to be set in MAX7219 register
|
||||
spi_set_nss_high(SPI(LED_MAX7219_SPI));
|
||||
// default setting
|
||||
led_max7219_off(); // switch display off
|
||||
led_max7219_test(false); // disable test mode
|
||||
led_max7219_intensity(15); // set maximum intensity
|
||||
led_max7219_write(0x0B07); // set scan limit to display all 7 digits
|
||||
}
|
||||
|
||||
void led_max7219_on(void)
|
||||
{
|
||||
led_max7219_write(0x0B70); // set scan limit to display all 7 digits
|
||||
led_max7219_write(0x0C01); // set scan limit to display all 7 digits
|
||||
}
|
||||
|
||||
void led_max7219_off(void)
|
||||
|
@ -229,7 +228,8 @@ void led_max7219_text(char* text)
|
|||
return;
|
||||
}
|
||||
}
|
||||
led_max7219_write(0x0900); // disable BCD decoding on all 7 digits
|
||||
for (uint8_t i=0; i<8; i++) { // display text
|
||||
led_max7219_write(((i+1)<<8)+(ascii_7segments[text[i]&0x7f])+(text[i]&0x80)); // send digit
|
||||
led_max7219_write(((i+1)<<8)+(ascii_7segments[(text[7-i]&0x7f)-' '])+(text[7-i]&0x80)); // send digit (in reverse order)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||
* @date 2017
|
||||
* @note peripherals used: GPIO @ref led_max7219_gpio, SPI @ref led_max7219_spi
|
||||
* @warning all calls are blocking
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
|
Loading…
Reference in New Issue