-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpiso.c
53 lines (40 loc) · 1.45 KB
/
piso.c
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
/*
Copyright (c) 2015,2016 Piotr Stolarz
librasp: RPi HW interface library
Distributed under the 2-clause BSD License (the License)
see accompanying file LICENSE for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
*/
/* Read PISO shift register example.
This code was tested on 74165 TI shift reg. with SH/LD, CLK and DATA pins
connected to GPIOs as defined by GPIO_XXX defs. CLK-INH is not used and must
be pulled to the ground.
*/
#include <stdio.h>
#include "librasp/devices/shr_piso.h"
/* GPIOs connected to the SHR */
#define GPIO_SH_LD 21
#define GPIO_CLK 20
#define GPIO_DATA 26
/* number of parallel inputs to be read */
#define INPUTS 10
int main(void)
{
gpio_hndl_t gpio_h;
if (gpio_init(&gpio_h, gpio_drv_io)==LREC_SUCCESS)
{
uint8_t dta[RNDUP8(INPUTS)/8];
char hex[2*sizeof(dta)+4];
shr_piso_gpio_init(&gpio_h, GPIO_SH_LD, GPIO_CLK, GPIO_DATA);
gpio_bcm_set_pull_config(&gpio_h, GPIO_DATA, gpio_bcm_pull_down);
shr_piso_read(&gpio_h, GPIO_SH_LD, GPIO_CLK, GPIO_DATA, INPUTS, dta);
bts2hex(dta, sizeof(dta), hex);
printf("data: %s\n", hex);
/* protect the out pins */
gpio_direction_input(&gpio_h, GPIO_SH_LD);
gpio_direction_input(&gpio_h, GPIO_CLK);
}
return 0;
}