Skip to content

Commit d622fd2

Browse files
author
shashankmarch27
committed
added a basic main page
1 parent 491289d commit d622fd2

File tree

4 files changed

+201
-8
lines changed

4 files changed

+201
-8
lines changed

Docs/index.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
@mainpage
2+
DriveMaster is a common library designed to simplify the implementation of RC protocol decoding in Arduino projects. It provides a modular and extensible architecture that allows for easy integration of various RC protocols.
3+
4+
# Supported Protocol
5+
6+
- [DShot300](#dshot300)
7+
- [DShot600](#dshot600)
8+
9+
## DShot300 {#dshot300}
10+
11+
### Configuration
12+
13+
- Baud rate: 100000
14+
- Data bits: 8 Bits
15+
- Parity: Even Parity
16+
- Stop bits: 2 Stop bits
17+
- Signal polarity: Inverted
18+
19+
## DShot600 {#dshot600}
20+
21+
### Configuration
22+
23+
- Baud rate: 420000
24+
- Data bits: 8 Bits
25+
- Parity: No Parity
26+
- Stop bits: 1 Stop bits
27+
- Signal polarity: Uninverted
28+
29+
# Getting Started
30+
- [Installation](#installation)
31+
- [Tutorial](#tutorial)
32+
- [Examples](#example)
33+
34+
# Installation {#installation}
35+
36+
## Arduino Installation
37+
38+
To use the DriveMaster library in your Arduino projects, follow these installation steps:
39+
40+
1. Download the DriveMaster library from the [GitHub repository](https://github.com/Witty-Wizard/DriveMaster).
41+
2. Extract the downloaded ZIP file.
42+
3. Copy the extracted folder to the `libraries` directory in your Arduino sketchbook.
43+
4. Restart the Arduino IDE.
44+
5. You should now be able to include the DriveMaster library in your Arduino sketches.
45+
46+
## PlatformIO Installation
47+
48+
If you are using PlatformIO, you can install the DriveMaster library directly from the PlatformIO Library Manager. Add the following line to your `platformio.ini` file:
49+
50+
```ini
51+
lib_deps = Witty-Wizard/DriveMaster @ ^0.1.0
52+
```
53+
# Tutorial {#tutorial}
54+
55+
## Using DriveMaster Library for Motor Control
56+
57+
To control motors in your Arduino project using the DriveMaster library, follow these steps:
58+
59+
1. **Include Necessary Libraries**
60+
61+
Include the required library at the beginning of your sketch:
62+
```cpp
63+
#include <DriveMaster.h>
64+
```
65+
66+
2. **Instantiate DriveMaster Object**
67+
Create an instance of the DriveMaster class, specifying the pin connected to the motor:
68+
69+
```cpp
70+
Copy code
71+
DriveMaster *motor = new DriveMaster(motorPin);
72+
```
73+
74+
3. **Initialize Motor Control**
75+
Call the begin() method to initialize motor control:
76+
77+
```cpp
78+
void setup() {
79+
motor->begin();
80+
}
81+
```
82+
83+
5. **Send Commands or Values**
84+
You can use the sendCommand() or sendValue() methods to send specific commands or values to the motor:
85+
86+
```cpp
87+
// Send a specific command to the motor
88+
motor->sendCommand(1000);
89+
90+
// Send a value directly to the motor
91+
motor->sendValue(512);
92+
```
93+
94+
# Examples {#example}
95+
96+
## DShot Example
97+
@include "../examples/basic_dshot/basic_dshot.ino"
98+
99+
# License
100+
This library is distributed under the GNU [General Public License version 3.0](https://www.gnu.org/licenses/gpl-3.0.html).

examples/basic_dshot/basic_dshot.ino

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*!
2+
* @file basic_dshot.ino
3+
*/
4+
#include <DriveMaster.h>
5+
6+
#define MOTOR_PIN 9
7+
8+
DriveMaster *motor;
9+
10+
void setup() {
11+
motor = new DriveMaster(MOTOR_PIN);
12+
motor->begin();
13+
}
14+
15+
void loop() {
16+
// Example: Set motor speed to 50% duty cycle
17+
motor->sendValue(512);
18+
delay(1000); // Delay for 1 second
19+
}

src/DriveMaster.h

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,51 @@
1+
/**
2+
* @file DriveMaster.h
3+
* @brief Header file for the DriveMaster class.
4+
*/
5+
16
#pragma once
27
#ifndef DRIVEMASTER_H
38
#define DRIVEMASTER_H
49

510
#include <Arduino.h>
611

12+
/**
13+
* @brief Base class for motor control.
14+
*/
715
class DriveMaster {
816
public:
17+
/**
18+
* @brief Construct a new DriveMaster object with the specified pin.
19+
* @param pin The pin number for motor control.
20+
*/
921
DriveMaster(int pin);
22+
/**
23+
* @brief Destroy the DriveMaster object.
24+
*/
1025
virtual ~DriveMaster();
26+
/**
27+
* @brief Initialize the motor control.
28+
*/
1129
virtual void begin();
30+
/**
31+
* @brief Write a command to the motor.
32+
* @param value The command value to write.
33+
* @param telemetry Flag indicating telemetry presence.
34+
*/
1235
virtual void write(uint16_t value, bool telemetery = false);
36+
/**
37+
* @brief Send a command to the motor.
38+
* @param value The command value to send.
39+
*/
1340
virtual void sendCommand(uint16_t value);
41+
/**
42+
* @brief Send a value to the motor.
43+
* @param value The value to send.
44+
*/
1445
virtual void sendValue(uint16_t value);
1546

1647
protected:
17-
int _pin;
48+
int _pin; /**< Pin number for motor control. */
1849
};
1950
#include "dshot.h"
2051
#endif

src/dshot.h

+50-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @file dshot.h
3+
* @brief Header file for the dshot class.
4+
*/
5+
16
#pragma once
27
#ifndef DSHOT_H
38
#define DSHOT_H
@@ -6,24 +11,62 @@
611
#include <esp32-hal-rmt.h>
712
#define DSHOT_FRAME_LENGTH 16
813

9-
enum DShotType { DSHOT_150, DSHOT_300 };
14+
/**
15+
* @brief Enumeration for different DShot types.
16+
*/
17+
enum DShotType {
18+
DSHOT_150, /**< DShot150 protocol */
19+
DSHOT_300 /**< DShot300 protocol */
20+
};
1021

22+
/**
23+
* @brief Class representing DShot communication.
24+
*/
1125
class dshot : public DriveMaster {
1226
private:
13-
rmt_obj_t *_channel = nullptr;
14-
rmt_data_t _data[DSHOT_FRAME_LENGTH];
15-
uint16_t _timingDuration0;
16-
uint16_t _timingDuration1;
17-
uint16_t _timingDurationBit;
27+
rmt_obj_t *_channel = nullptr; /**< RMT channel for DShot communication */
28+
rmt_data_t _data[DSHOT_FRAME_LENGTH]; /**< RMT data array for DShot frames */
29+
uint16_t _timingDuration0; /**< Timing duration for logic 0 */
30+
uint16_t _timingDuration1; /**< Timing duration for logic 1 */
31+
uint16_t _timingDurationBit; /**< Timing duration for a bit */
32+
/**
33+
* @brief Calculate the CRC (Cyclic Redundancy Check) for the given DShot
34+
* command value.
35+
* @param value DShot command value
36+
* @return Calculated CRC value
37+
*/
1838
uint8_t calculateCrc(uint16_t value);
39+
/**
40+
* @brief Write a DShot frame with the specified value and telemetry flag.
41+
* @param value DShot value to write
42+
* @param telemetry Flag indicating telemetry presence
43+
*/
1944
void write(uint16_t value, bool telemetery = false);
2045

2146
public:
47+
/**
48+
* @brief Construct a new dshot object with the specified pin and DShot type.
49+
* @param pin Pin to use for DShot communication
50+
* @param type DShot protocol type (DSHOT_150 or DSHOT_300)
51+
*/
2252
explicit dshot(int pin, DShotType type = DSHOT_300);
53+
/**
54+
* @brief Destroy the dshot object.
55+
*/
2356
~dshot();
24-
57+
/**
58+
* @brief Initialize the DShot communication.
59+
*/
2560
void begin() override;
61+
/**
62+
* @brief Send a DShot command with telemetry enabled.
63+
* @param value DShot command value
64+
*/
2665
void sendCommand(uint16_t value) override;
66+
/**
67+
* @brief Send a DShot value with telemetry disabled.
68+
* @param value DShot value to send
69+
*/
2770
void sendValue(uint16_t value) override;
2871
};
2972

0 commit comments

Comments
 (0)