8000 Sun Mar 5 11:14:27 CST 2017 · mwerschy/esp32-snippets@183cb9c · GitHub
[go: up one dir, main page]

Skip to content

Commit 183cb9c

Browse files
author
kolban
committed
Sun Mar 5 11:14:27 CST 2017
1 parent 79c382a commit 183cb9c

29 files changed

+991
-113
lines changed

cpp_utils/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ SEPARATE_MEMBER_PAGES = NO
226226
# uses this value to replace tabs by spaces in code fragments.
227227
# Minimum value: 1, maximum value: 16, default value: 4.
228228

229-
TAB_SIZE = 4
229+
TAB_SIZE = 3
230230

231231
# This tag can be used to specify a number of aliases that act as commands in
232232
# the documentation. An alias has the form:

cpp_utils/FreeRTOS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ void FreeRTOS::deleteTask(TaskHandle_t pTask) {
4747
}
4848

4949
/**
50-
* Get the time in milliseconds since the FreeRTOS scheduler started.
51-
* @return The time in milliseconds since the FreeRTOS scheduler started.
50+
* Get the time in milliseconds since the %FreeRTOS scheduler started.
51+
* @return The time in milliseconds since the %FreeRTOS scheduler started.
5252
*/
5353
uint32_t FreeRTOS::getTimeSinceStart() {
5454
return (uint32_t)(xTaskGetTickCount()*portTICK_PERIOD_MS);

cpp_utils/FreeRTOS.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <freertos/FreeRTOS.h>
1414
#include <freertos/task.h>
1515

16+
/**
17+
* @brief Interface to %FreeRTOS functions.
18+
*/
1619
class FreeRTOS {
1720
public:
1821
FreeRTOS();

cpp_utils/GPIO.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,47 @@
66
*/
77

88
#include "GPIO.h"
9+
#include <driver/gpio.h>
910

11+
/**
12+
* @brief Class instance constructor.
13+
*/
1014
GPIO::GPIO() {
1115
// TODO Auto-generated constructor stub
1216

1317
}
1418

1519
/**
16-
* Determine if the pin is a valid pin for an ESP32 (i.e. is it in range).
20+
* @brief Determine if the pin is a valid pin for an ESP32 (i.e. is it in range).
21+
*
1722
* @param [in] pin The pin number to validate.
1823
* @return The value of true if the pin is valid and false otherwise.
1924
*/
20-
bool GPIO::inRange(int pin) {
25+
bool GPIO::inRange(gpio_num_t pin) {
2126
if (pin>=0 && pin<=39) {
2227
return true;
2328
}
2429
return false;
2530
}
31+
32+
/**
33+
* @brief Read a value from the given pin.
34+
* @param [in] pin The pin to read from.
35+
*/
36+
bool GPIO::read(gpio_num_t pin) {
37+
return ::gpio_get_level(pin);
38+
}
39+
40+
41+
/**
42+
* @brief Write a value to the given pin.
43+
*
44+
* @param [in] pin The gpio pin to change.
45+
* @param [out] value The value to be written to the pin.
46+
*/
47+
void GPIO::write(gpio_num_t pin, bool value) {
48+
::gpio_set_level(pin, value);
49+
}
50+
51+
52+

cpp_utils/GPIO.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88
#ifndef COMPONENTS_CPP_UTILS_GPIO_H_
99
#define COMPONENTS_CPP_UTILS_GPIO_H_
10-
10+
#include <driver/gpio.h>
11+
/**
12+
* @brief Interface to GPIO functions.
13+
*/
1114
class GPIO {
1215
public:
1316
GPIO();
14-
static bool inRange(int pin);
17+
static bool inRange(gpio_num_t pin);
18+
static bool read(gpio_num_t pin);
19+
static void write(gpio_num_t pin, bool value);
20+
1521
};
1622

1723
#endif /* COMPONENTS_CPP_UTILS_GPIO_H_ */

cpp_utils/I2C.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515

1616
/**
17-
* Create an instance of an I2C object.
17+
* @brief Create an instance of an %I2C object.
18+
*
1819
* @param[in] sdaPin The pin number used for the SDA line.
1920
* @param[in] sclPin The pin number used for the SCL line.
2021
*/
@@ -35,7 +36,9 @@ I2C::I2C(int sdaPin, int sclPin) {
3536

3637

3738
/**
38-
* Begin a new I2C transaction.
39+
* @brief Begin a new %I2C transaction.
40+
*
41+
* Begin a transaction by sending a start.
3942
*/
4043
void I2C::beginTransaction() {
4144
cmd = i2c_cmd_link_create();
@@ -44,9 +47,10 @@ void I2C::beginTransaction() {
4447
}
4548

4649
/**
47-
* End an I2C transaction.
48-
* This call will execute the I2C requests that have been queued up since the preceding call to the
49-
* `beginTransaction()` function.
50+
* @brief End an I2C transaction.
51+
*
52+
* This call will execute the %I2C requests that have been queued up since the preceding call to the
53+
* beginTransaction() function. An %I2C stop() is also called.
5054
*/
5155
void I2C::endTransaction() {
5256
ESP_ERROR_CHECK(i2c_master_stop(cmd));
@@ -56,9 +60,10 @@ void I2C::endTransaction() {
5660

5761

5862
/**
59-
* Write a single byte to the I2C slave.
63+
* @brief Write a single byte to the %I2C slave.
64+
*
6065
* @param[in] byte The byte to write to the slave.
61-
* @param[in] ack Whether or not an acknowledgement is expected from the slave.
66+
* @param[in] ack Whether or not an acknowledgment is expected from the slave.
6267
*/
6368
void I2C::write(uint8_t byte, bool ack) {
6469
if (directionKnown == false) {
@@ -69,10 +74,11 @@ void I2C::write(uint8_t byte, bool ack) {
6974
}
7075

7176
/**
72-
* Write a sequence of byte to the I2C slave.
73-
* @param[in] bytes The sequence of bytes to write to the I2C slave.
77+
* @brief Write a sequence of byte to the %I2C slave.
78+
*
79+
* @param[in] bytes The sequence of bytes to write to the %I2C slave.
7480
* @param[in] length The number of bytes to write.
75-
* @param[in] ack Whether or not an acknowledgement is expected from the slave.
81+
* @param[in] ack Whether or not an acknowledgment is expected from the slave.
7682
*/
7783
void I2C::write(uint8_t *bytes, size_t length, bool ack) {
7884
if (directionKnown == false) {
@@ -84,14 +90,15 @@ void I2C::write(uint8_t *bytes, size_t length, bool ack) {
8490

8591

8692
/**
87-
* Add an I2C start request to the command stream.
93+
* @brief Add an I2C start request to the command stream.
8894
*/
8995
void I2C::start() {
9096
ESP_ERROR_CHECK(i2c_master_start(cmd));
9197
}
9298

9399
/**
94-
* Read a single byte from the slave.
100+
* @brief Read a single byte from the slave.
101+
*
95102
* @param[out] byte The address into which the read byte will be stored.
96103
* @param[in] ack Whether or not we should send an ACK to the slave after reading a byte.
97104
*/
@@ -104,7 +111,8 @@ void I2C::readByte(uint8_t* byte, bool ack) {
104111
}
105112

106113
/**
107-
* Read a sequence of bytes from the slave.
114+
* @brief Read a sequence of bytes from the slave.
115+
*
108116
* @param[out] byte The address into which the read bytes will be stored.
109117
* @param[in] length The number of expected bytes to read.
110118
* @param[in] ack Whether or not we should send an ACK to the slave after reading a byte.
@@ -119,7 +127,7 @@ void I2C::read(uint8_t* bytes, size_t length, bool ack) {
119127

120128

121129
/**
122-
* Add an I2C stop request to the command stream.
130+
* @brief Add an %I2C stop request to the command stream.
123131
*/
124132
void I2C::stop() {
125133
ESP_ERROR_CHECK(i2c_master_stop(cmd));

cpp_utils/I2C.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include <sys/types.h>
1212
#include <driver/i2c.h>
1313

14+
15+
/**
16+
* @brief Interface to %I2C functions.
17+
*/
1418
class I2C {
1519
private:
1620
uint8_t address;
@@ -21,30 +25,32 @@ class I2C {
2125
I2C(int sdaPin, int sclPin);
2226
void beginTransaction();
2327
void endTransaction();
24-
void write(uint8_t byte, bool ack=true);
25-
void write(uint8_t *bytes, size_t length, bool ack=true);
26-
void readByte(uint8_t *byte, bool ack=true);
27-
void read(uint8_t *bytes, size_t length, bool ack=true);
28-
void start();
29-
void stop();
30-
3128
/**
32-
* Get the address of the I2C slave against which we are working.
33-
* @return The address of the I2C slave.
29+
* @brief Get the address of the %I2C slave against which we are working.
30+
*
31+
* @return The address of the %I2C slave.
3432
*/
3533
uint8_t getAddress() const
3634
{
3735
return address;
3836
}
3937

38+
void read(uint8_t *bytes, size_t length, bool ack=true);
39+
void readByte(uint8_t *byte, bool ack=true);
40+
4041
/**
41-
* Set the address of the I2C slave against which we will be working.
42-
* @param[in] address The address of the I2C slave.
42+
* @brief Set the address of the %I2C slave against which we will be working.
43+
*
44+
* @param[in] address The address of the %I2C slave.
4345
*/
4446
void setAddress(uint8_t address)
4547
{
4648
this->address = address;
4749
}
50+
void start();
51+
void stop();
52+
void write(uint8_t byte, bool ack=true);
53+
void write(uint8_t *bytes, size_t length, bool ack=true);
4854
};
4955

5056
#endif /* MAIN_I2C_H_ */

cpp_utils/MPU6050.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define MPU6050_PWR_MGMT_1 0x6B
1313

1414
/**
15-
* Construct an MPU6050 handler.
15+
* @brief Construct an MPU6050 handler.
1616
*/
1717
MPU6050::MPU6050() {
1818
i2c = new I2C(PIN_SDA, PIN_CLK);
@@ -31,13 +31,19 @@ MPU6050::MPU6050() {
3131
}
3232

3333

34+
/**
35+
* @brief Destory the class instance.
36+
*/
3437
MPU6050::~MPU6050() {
3538
delete i2c;
3639
}
3740

3841

3942
/**
40-
* Read the acceleration value from the device.
43+
* @brief Read the acceleration value from the device.
44+
*
45+
* Calling this method results in communication with the device to retrieve the
46+
* acceleration data that is then stored in the class instance ready for retrieval.
4147
*/
4248
void MPU6050::readAccel() {
4349
i2c->beginTransaction();
@@ -56,7 +62,10 @@ void MPU6050::readAccel() {
5662
} // readAccel
5763

5864
/**
59-
* Read the gyroscopic values from the device.
65+
* @brief Read the gyroscopic values from the device.
66+
*
67+
* Calling this method results in communication with the device to retrieve the
68+
* gyroscopic data that is then stored in the class instance ready for retrieval.
6069
*/
6170
void MPU6050::readGyro() {
6271
i2c->beginTransaction();

cpp_utils/MPU6050.h

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
/**
2-
* Encapsulate the MPU6050.
3-
*
4-
* This class encapsulates the MPU6050 accelerometer and gyroscope.
5-
* The MPU6050 uses I2C as the communication between the master and the slave.
6-
*/
7-
8-
91
#ifndef MAIN_MPU6050_H_
102
#define MAIN_MPU6050_H_
113
#include "I2C.h"
124

5+
/**
6+
* @brief Driver for the MPU6050 accelerometer and gyroscope.
7+
*
8+
* The MPU6050 uses I2C as the communication between the master and the slave. The class stores
9+
* the last read values as class instance local data. The data can be retrieved from the class
10+
* using the appropriate getters. The readAccel() and readGyro() methods cause communication
11+
* with the device to retrieve and locally hold the values from the device.
12+
*/
1313
class MPU6050 {
1414
private:
1515
I2C *i2c;
@@ -19,60 +19,52 @@ class MPU6050 {
1919
MPU6050();
2020
virtual ~MPU6050();
2121

22-
/**
23-
* Read the acceleration values from the MPU-6050.
24-
*/
2522
void readAccel();
2623

27-
/**
28-
* Read the gyor values from the MPU-6050.
29-
*/
3024
void readGyro();
3125

3226
/**
33-
* Retrieve the X acceleration value.
27+
* @brief Get the X acceleration value.
3428
*/
3529
short getAccelX() const
3630
{
3731
return accel_x;
3832
}
3933

4034
/**
41-
* Retrieve the Y acceleration value.
35+
* @brief Get the Y acceleration value.
4236
*/
4337
short getAccelY() const
4438
{
4539
return accel_y;
4640
}
4741

4842
/**
49-
* Retrieve the Z acceleration value.
43+
* @brief Get the Z acceleration value.
5044
*/
5145
short getAccelZ() const
5246
{
5347
return accel_z;
5448
}
5549

5650
/**
57-
* Retrieve X gyro value.
51+
* @brief Get the X gyroscopic value.
5852
*/
5953
short getGyroX() const
6054
{
6155
return gyro_x;
6256
}
6357

64-
6558
/**
66-
* Retrieve Y gyro value.
59+
* @brief Get the Y gyroscopic value.
6760
*/
6861
short getGyroY() const
6962
{
7063
return gyro_y;
7164
}
7265

73-
7466
/**
75-
* Retrieve Z gyro value.
67+
* @brief Get the Z gyroscopic value.
7668
*/
7769
short getGyroZ() const
7870
{

0 commit comments

Comments
 (0)
0