Skip to content

Commit ee26de2

Browse files
committed
add gpio and rtc function
1 parent bb09f20 commit ee26de2

File tree

560 files changed

+47380
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

560 files changed

+47380
-0
lines changed

NexGpio.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @file NexGpio.cpp
3+
*
4+
* The implementation of class NexGpio.
5+
*
6+
* @author Wu Pengfei (email:<[email protected]>)
7+
* @date 2015/8/13
8+
* @copyright
9+
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
10+
* This program is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License as
12+
* published by the Free Software Foundation; either version 2 of
13+
* the License, or (at your option) any later version.
14+
*/
15+
#include "NexGpio.h"
16+
17+
bool NexGpio::pin_mode(uint32_t port,uint32_t mode,uint32_t control_id)
18+
{
19+
char buf;
20+
String cmd;
21+
22+
cmd += "cfgpio ";
23+
buf = port + '0';
24+
cmd += buf;
25+
cmd += ',';
26+
buf = mode + '0';
27+
cmd += buf;
28+
cmd += ',';
29+
buf = control_id = '0';
30+
cmd += buf;
31+
32+
sendCommand(cmd.c_str());
33+
return recvRetCommandFinished();
34+
35+
}
36+
37+
bool NexGpio::digital_write(uint32_t port,uint32_t value)
38+
{
39+
String cmd;
40+
char buf;
41+
42+
cmd += "pio";
43+
buf = port + '0';
44+
cmd += buf;
45+
cmd += '=';
46+
buf = value + '0';
47+
cmd += buf;
48+
49+
sendCommand(cmd.c_str());
50+
return recvRetCommandFinished();
51+
}
52+
53+
uint32_t NexGpio::digital_read(uint32_t port)
54+
{
55+
uint32_t number;
56+
char buf;
57+
58+
String cmd = String("get ");
59+
cmd += "pio";
60+
buf = port + '0';
61+
cmd += buf;
62+
63+
sendCommand(cmd.c_str());
64+
recvRetNumber(&number);
65+
return number;
66+
}
67+
68+
bool NexGpio::analog_write(uint32_t port,uint32_t value)
69+
{
70+
char buf[10] = {0};
71+
char c;
72+
String cmd;
73+
74+
utoa(value, buf, 10);
75+
cmd += "pwm";
76+
c = port + '0';
77+
cmd += c;
78+
cmd += '=';
79+
cmd += buf;
80+
81+
Serial.print(cmd);
82+
sendCommand(cmd.c_str());
83+
return recvRetCommandFinished();
84+
}
85+
86+
bool NexGpio::set_pwmfreq(uint32_t value)
87+
{
88+
char buf[10] = {0};
89+
String cmd;
90+
91+
utoa(value, buf, 10);
92+
cmd += "pwmf";
93+
cmd += '=';
94+
cmd += buf;
95+
96+
sendCommand(cmd.c_str());
97+
return recvRetCommandFinished();
98+
}
99+
100+
uint32_t NexGpio::get_pwmfreq(uint32_t *number)
101+
{
102+
String cmd = String("get pwmf");
103+
sendCommand(cmd.c_str());
104+
return recvRetNumber(number);
105+
}

NexGpio.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#ifndef _NEXGPIO_H
2+
#define _NEXGPIO_H
3+
4+
#include "NexTouch.h"
5+
#include "NexHardware.h"
6+
7+
8+
class NexGpio
9+
{
10+
public:
11+
/**
12+
* Set gpio mode
13+
*
14+
* @param port - the gpio port number
15+
* @param mode - set gpio port mode(0--Pull on the input
16+
* 1--the control input binding
17+
* 2--Push-pull output
18+
* 3--pwm output
19+
* 4--open mode leakage)
20+
* @param control_id - nextion controls id ,when the modeel is 1 to be valid
21+
* @return true if success, false for failure
22+
*/
23+
24+
bool pin_mode(uint32_t port,uint32_t mode,uint32_t control_id);
25+
26+
/**
27+
* write a high or a LOW value to a digital pin
28+
*
29+
* @param port - the gpio port number
30+
* @param mode - the gpio port number
31+
* @return true if success, false for failure
32+
*/
33+
34+
bool digital_write(uint32_t port,uint32_t value);
35+
36+
/**
37+
* read a high or a LOW value to a digital pin
38+
*
39+
* @param port - the gpio port number
40+
* @return the value from a specified digital pin, either high or low
41+
*/
42+
43+
uint32_t digital_read(uint32_t port);
44+
45+
/**
46+
* writes an analog value (PWM wave) to a pin
47+
*
48+
* @param port - the gpio port number
49+
* @param value - the duty cycle: between 0 (always off) and 100 (always on).
50+
* @return true if success, false for failure
51+
*/
52+
53+
bool analog_write(uint32_t port,uint32_t value);
54+
55+
/**
56+
* writes pwm output frequency
57+
*
58+
* @param value - the frequency: between 1 and 65535
59+
* @return true if success, false for failure
60+
*/
61+
62+
bool set_pwmfreq(uint32_t value);
63+
64+
/**
65+
* read pwm output frequency
66+
*
67+
* @param number - the frequency
68+
* @return true if success, false for failure
69+
*/
70+
71+
uint32_t get_pwmfreq(uint32_t *number);
72+
73+
/**
74+
* write rtc times
75+
*
76+
* @param time - Time to write to the array
77+
* @return true if success, false for failure
78+
*/
79+
80+
};
81+
82+
#endif

0 commit comments

Comments
 (0)