-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathic74hc595.h
93 lines (77 loc) · 1.7 KB
/
ic74hc595.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @file ic74hc595.h
* @author Jaime Albuquerque ([email protected])
* @brief Output shifter register library
* @version 0.1
* @date 2022-09-27
*
* @copyright Copyright (c) 2022
*
*/
#if !defined(_IC74HC595_H_)
#define _IC74HC595_H_
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#if defined(IDF_VER) // Settings for ESP-IDF
#include "driver/gpio.h"
#include "esp32/rom/ets_sys.h"
#define SETPIN(PIN) gpio_set_level(PIN, 1)
#define CLRPIN(PIN) gpio_set_level(PIN, 0)
#define _DELAY_US(x) ets_delay_us(x)
#endif // IDF_VER
typedef struct {
uint8_t num_reg; // Number of shift registers
uint8_t *reg_value; // Last value of all registers
// GPIO
struct pin {
#if defined(IDF_VER)
gpio_num_t clk;
gpio_num_t signal;
gpio_num_t latch;
#else // IDF_VER
uint8_t clk;
uint8_t signal;
uint8_t latch;
#endif // Generic
} pin;
} shift_reg_config_t;
/**
* @brief Initialize the microcontroller to do the output
*
* @param shft
* @return < 0 means error
*/
int8_t ic74hc595_init(shift_reg_config_t *shft);
/**
* @brief
*
* @param shft
* @return int8_t
*/
int8_t ic74hc595_deinit(shift_reg_config_t *shft);
/**
* @brief Send the whole data
*
* @param data
* @param len
* @param shft
* @return -1 = data longer than number of registers; 1 = successfully sent
*/
int8_t ic74hc595_send(uint8_t *data, uint8_t len, shift_reg_config_t *shft);
/**
* @brief Send 1 byte at a time
*
* @param data
* @param shft
* @return int8_t
*/
int8_t ic74hc595_send8bits(uint8_t data, shift_reg_config_t *shft);
/**
* @brief Latch the registers
*
* @param shft
* @return int8_t
*/
int8_t ic74hc595_latch(shift_reg_config_t *shft);
#endif // _IC74HC595_H_