-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPicoTM1637.pio
105 lines (82 loc) · 2.39 KB
/
PicoTM1637.pio
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PROGRAM OVERVIEW:
;
; START * SET (write mode or display controll)
; SHIFT *
; ACK *
; STOP *
; if OSR EMPTY DONE
; START - SET ADDRESS
; SHIFT -
; ACK -
; SHIFT * SEND DATA
; ACK *
; STOP *
; if OSR NOT EMPTY SEND DATA AGAIN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.program tm1637
.side_set 1 opt
set pins, 1 side 1
_start:
pull block
; SET WRITE MODE / DISPLAY CONTROLL
_startCond:
set x, 7
set pins, 1 side 1 [7]
set pins, 0
set pins, 0 side 0
_bitShiftLoop:
out pins, 1 side 0
nop side 1
jmp x-- _bitShiftLoop side 0
_ackCond:
set pins, 0 side 0
nop side 1
nop side 0 [1]
_stopCond:
set pins, 0 side 1
set pins, 1 side 1
jmp !OSRE _startCond_sendDigit ; If there only was 1 byte of data in OSR
; end here, otherwise continue and send data
jmp _start
; SET ADDRESS, SEND DATA
_startCond_sendDigit:
set pins, 1 side 1 [7]
set pins, 0
set pins, 0 side 0
_sendCmdAndData:
set x, 7
_bitShiftLoop_sendDigit:
out pins, 1 side 0
nop side 1
jmp x-- _bitShiftLoop_sendDigit side 0
_ackCond_sendDigit:
set pins, 0 side 0
nop side 1
nop side 0 [1]
; If there is data left continue sending digits
jmp !OSRE _sendCmdAndData
_stopCond_sendDigit:
set pins, 0 side 1
set pins, 1 side 1
% c-sdk {
static inline void tm1637_program_init(PIO pio, uint sm, uint offset, uint pin_SCL, uint pin_SDA) {
pio_sm_config c = tm1637_program_get_default_config(offset);
gpio_pull_up(pin_SCL);
gpio_pull_up(pin_SDA);
pio_gpio_init(pio, pin_SCL);
pio_gpio_init(pio, pin_SDA);
sm_config_set_sideset_pins(&c, pin_SCL);
uint32_t both_pins = (1u << pin_SCL) | (1u << pin_SDA);
pio_sm_set_pins_with_mask(pio, sm, both_pins, both_pins);
pio_sm_set_pindirs_with_mask(pio, sm, both_pins, both_pins);
sm_config_set_out_pins(&c, pin_SDA, 1);
sm_config_set_set_pins(&c, pin_SDA, 1);
sm_config_set_out_shift(&c, true, false, 32);
sm_config_set_clkdiv(&c, (float)(24000000/1000)); // The slowest clock possible!
// Load our configuration, and jump to the start of the program
pio_sm_init(pio, sm, offset, &c);
// Set the state machine running
pio_sm_set_enabled(pio, sm, true);
}
%}