-
Notifications
You must be signed in to change notification settings - Fork 0
/
seven_seg.h
75 lines (62 loc) · 1.73 KB
/
seven_seg.h
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
/**
* @file seven_seg.h
* @author Hamid Salehi ([email protected]) * @brief
* @date 2023-03-18
*
*/
#ifndef SEVEN_SEG_H_
#define SEVEN_SEG_H_
#include "io_define.h"
#include "seven_seg_config.h"
/**
* @brief Hold sevenSeg io
* *user can change it to GPIO_TypeDef or anything else that system want
*/
typedef GPIO_TypeDef* SevenSeg_IO;
/**
* @brief Hold kesevenSegy pin num or pin bit
* *user can change it to uint8_t for 8-bit systems like AVR
*/
typedef uint16_t SevenSeg_pin;
/**
* @brief Hold pin configuration that use for handle 7seg pins
*/
typedef struct {
SevenSeg_IO IO;
SevenSeg_pin pin;
} SevenSeg_pinConfig;
/**
* @brief Initialize pin in output mode
*/
typedef void (*SevenSeg_initPinFn)(const SevenSeg_pinConfig* config);
/**
* @brief Set pin state
*/
typedef void (*SevenSeg_writePinFn)(const SevenSeg_pinConfig* config, GPIO_PinState state);
/**
* @brief hold minimum function for sevenSeg lib to work
*/
typedef struct {
SevenSeg_initPinFn initPin;
SevenSeg_writePinFn writePin;
} SevenSeg_Driver;
typedef struct {
SevenSeg_pinConfig* dataBus;
SevenSeg_pinConfig* comBus;
#if USE_DYNAMIC_MEMORY
uint8_t* digit;
#else
uint8_t digit[SEVEN_SEG_DIGIT_MAX_NUM];
#endif //USE_DYNAMIC_MEMORY
uint8_t digitNum;
uint8_t currentDigit;
}SevenSegment;
#pragma used+
void sevenSegInit(SevenSeg_Driver* driver);
void sevenSegAdd(SevenSegment* sg, SevenSeg_pinConfig* dataBus, SevenSeg_pinConfig* comBus, uint8_t digitsNum);
void sevenSegPutInt(SevenSegment* sg, uint32_t num);
void sevenSegPuts(SevenSegment* sg, char* str);
void sevenSegPutFloat(SevenSegment* sg, float num, uint8_t decimals);
void sevenSegRefreshIsr(void);
#pragma used-
#endif // SEVEN_SEG_H_