-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblink.c
64 lines (59 loc) · 2.24 KB
/
blink.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
54
55
56
57
58
59
60
61
62
63
64
/*--------------------------------------------------------------------------------------------
// Name: blink.c
//
// Synopsis: chip_xio is a basic application to drive the xio port on the C.H.I.P. Layered on
// the existing sysfs implementation for NON-RTA pin driving.
// At this time it only controls individual pin input or output. This code is not
// portable with other OS's without rewrite.
//
// GPIO Sysfs Interface for Userspace
// https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
//
// Next Thing Co. documentation.
// https://docs.getchip.com/chip.html#gpio
// Pins XIO-P0 to P7 linearly map to gpio408 to gpio415 on kernel 4.3 and gpio1016 to
// gpio1023 on kernel 4.4.11. For kernel 4.4.13-ntc-mlc the range is gpio1013 to
// gpio1019. See documentation to determine version.
//
// Please note this software is not warrantied and any resulting damage from its use is not
// the writers responsibility. Use at your own risk!
//
// Copyright (c) 2017 Ovide N. Mercure
---------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include "chip_xio.h"
// Test program
void main( void )
{
int i;
if( !chip_xio_start() )
return;
if( !export_pin( XIO_P4 ) )
return;
printf("Checking for direction------------------------------------------\n");
printf( "XIO_P4 Pin Direction is: %s\n", get_pin_direction( XIO_P4 ));
if( strcmp( get_pin_direction( XIO_P4 ), "in" ) == 0 )
{
printf( "Change input to output\n" );
set_pin_output( XIO_P4 );
}
else
{
printf( "Pin set for output\n" );
}
printf("Run test program------------------------------------------------\n");
for( i = 0 ; i < 10; i++ )
{
printf( "Setting XIO_P4 high\n");
set_pin_high( XIO_P4 );
printf( "XIO_P4 Pin Value is: %s\n", get_pin_value( XIO_P4 ) );
sleep( 1 );
printf("Setting XIO_P4 low\n");
set_pin_low( XIO_P4 );
printf( "XIO_P4 Pin Value is: %s\n", get_pin_value( XIO_P4 ) );
sleep( 1 );
}
printf( "Unexport pin XIO_P4\n" );
unexport_pin( XIO_P4 );
}