aboutsummaryrefslogtreecommitdiff
path: root/src/tm1637.h
blob: 0c1ed66a61736734493df08b8aabc811f2b33c9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once

#include <stdint.h>
#include <stdbool.h>

#define TM1637_FONT_0 (0x3f)
#define TM1637_FONT_1 (0x06)
#define TM1637_FONT_2 (0x5b)
#define TM1637_FONT_3 (0x4f)
#define TM1637_FONT_4 (0x66)
#define TM1637_FONT_5 (0x6d)
#define TM1637_FONT_6 (0x7d)
#define TM1637_FONT_7 (0x07)
#define TM1637_FONT_8 (0x7f)
#define TM1637_FONT_9 (0x6f)
#define TM1637_FONT_A (0x77)
#define TM1637_FONT_B (0x7c)
#define TM1637_FONT_C (0x39)
#define TM1637_FONT_D (0x5e)
#define TM1637_FONT_E (0x79)
#define TM1637_FONT_F (0x71)
#define TM1637_COLON (0x80)

typedef struct {
	uint8_t* data;
	uint32_t length;
} TM1637Sequence;

/** @brief configure registers for tm1637 */
void tm1637_begin();

/**
 * @brief configure display brightness
 * @param brightness display brightness from 0 (dim) to 7 (bright)
 * @param on whether the display is on
 */
void tm1637_dispcfg(uint8_t brightness, bool on);

/**
 * @brief send segment data to display
 * @param segment address segment 0-3
 * @param data data to set to segment where LSB=A and MSB-1=G. on segment 1 MSB=colon
 */
void tm1637_segmentsend(uint8_t segment, uint8_t data);

static const uint8_t tm1637_font[16] = {
	TM1637_FONT_0,
	TM1637_FONT_1,
	TM1637_FONT_2,
	TM1637_FONT_3,
	TM1637_FONT_4,
	TM1637_FONT_5,
	TM1637_FONT_6,
	TM1637_FONT_7,
	TM1637_FONT_8,
	TM1637_FONT_9,
	TM1637_FONT_A,
	TM1637_FONT_B,
	TM1637_FONT_C,
	TM1637_FONT_D,
	TM1637_FONT_E,
	TM1637_FONT_F,
};