aboutsummaryrefslogtreecommitdiff
path: root/src/tm1637.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-03-23 17:07:19 +0100
committerlonkaars <loek@pipeframe.xyz>2022-03-23 17:07:19 +0100
commit2155868ab3358535d4915f39dc192189bc57e938 (patch)
treeff418b5488a511fc26a7ab3a33f77226d5dd6681 /src/tm1637.c
parentb3344df3e3a3594f133c2c051df981d75e0112b8 (diff)
working display driver :tada:
Diffstat (limited to 'src/tm1637.c')
-rw-r--r--src/tm1637.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/tm1637.c b/src/tm1637.c
index 4e6e68c..9cc79d6 100644
--- a/src/tm1637.c
+++ b/src/tm1637.c
@@ -2,11 +2,6 @@
#include "tm1637.h"
#include "stm32f091xc.h"
-void _tm1637_micro_delay() {
- timer_delay(10);
- // for(unsigned int x = 0; x < 10e4; x++);
-}
-
/** @brief reset gpio mode registers for dio */
void _tm1637_GPIOMODE_reset() {
GPIOA->MODER &= ~(0b11 << (PINOUT_DISP_DIO * 2));
@@ -36,9 +31,6 @@ void _tm1637_GPIOMODE_open_drain() {
*/
void _tm1637_pin_write(uint32_t pin, bool state) {
GPIOA->ODR ^= (((GPIOA->ODR & (1 << pin)) >> pin) ^ state) << pin;
-
- if (pin == PINOUT_DISP_CLK) led_write(0, state);
- if (pin == PINOUT_DISP_DIO) led_write(1, state);
}
void tm1637_begin() {
@@ -50,31 +42,24 @@ void tm1637_begin() {
_tm1637_pin_write(PINOUT_DISP_CLK, 1);
_tm1637_pin_write(PINOUT_DISP_DIO, 1);
-
- _tm1637_micro_delay();
}
void _tm1637_start() {
_tm1637_pin_write(PINOUT_DISP_DIO, 0);
- _tm1637_micro_delay();
}
void _tm1637_stop() {
_tm1637_pin_write(PINOUT_DISP_CLK, 1);
_tm1637_pin_write(PINOUT_DISP_DIO, 1);
- _tm1637_micro_delay();
}
bool _tm1637_ack() {
_tm1637_pin_write(PINOUT_DISP_CLK, 0);
_tm1637_pin_write(PINOUT_DISP_DIO, 0);
_tm1637_GPIOMODE_open_drain();
- _tm1637_micro_delay();
_tm1637_pin_write(PINOUT_DISP_CLK, 1);
- _tm1637_micro_delay();
_tm1637_pin_write(PINOUT_DISP_CLK, 0);
_tm1637_GPIOMODE_gp_output();
- _tm1637_micro_delay();
return true;
}
@@ -90,21 +75,39 @@ TM1637Sequence _tm1637_send(TM1637Sequence command) {
for (uint32_t byte = 0; byte < command.length; byte++) {
for (uint8_t bit = 0; bit < 8; bit++) {
- uint8_t rev_bit = 7 - bit;
_tm1637_pin_write(PINOUT_DISP_CLK, 0);
- _tm1637_pin_write(PINOUT_DISP_DIO, (command.data[byte] & (1 << rev_bit)) >> rev_bit);
- _tm1637_micro_delay();
+ _tm1637_pin_write(PINOUT_DISP_DIO, (command.data[byte] & (1 << bit)) >> bit);
_tm1637_pin_write(PINOUT_DISP_CLK, 1);
- _tm1637_micro_delay();
}
//TODO: confirm ack
/*bool ack =*/ _tm1637_ack();
}
- _tm1637_micro_delay();
-
// stop condition
_tm1637_stop();
return response;
}
+
+void tm1637_dispcfg(uint8_t brightness, bool on) {
+ uint8_t dis_data[] = {
+ (uint8_t)(0b10000000 | (on << 3) | (brightness)),
+ };
+ TM1637Sequence seq = {
+ .data = dis_data,
+ .length = 1,
+ };
+ _tm1637_send(seq);
+}
+
+void tm1637_segmentsend(uint8_t segment, uint8_t data) {
+ uint8_t dis_data[] = {
+ (uint8_t)(0b11000000 | segment),
+ data,
+ };
+ TM1637Sequence seq = {
+ .data = dis_data,
+ .length = 2,
+ };
+ _tm1637_send(seq);
+}