Added first documentation
This commit is contained in:
+33
-47
@@ -1,56 +1,42 @@
|
||||
# Zephyr USB Command Handler
|
||||
# Servo controller for Servo2350 board
|
||||
|
||||
This repository contains the implementation of a USB command handler for the Zephyr RTOS. The system allows devices to communicate via USB using custom command messages.
|
||||
|
||||
### Components
|
||||
|
||||
1. **command_handler.c/h**: Handles incoming commands, processes them, and performs actions based on the command type.
|
||||
2. **command_message.c/h**: Manages the creation, validation, and logging of command messages, including CRC calculation.
|
||||
3. **usb.c/h**: Manages USB initialization, data reception via UART, and sending responses. Includes a USB thread.
|
||||
4. **usb_conf.c/h**: Configures the USB device.
|
||||
|
||||
### ACK
|
||||
|
||||
Every command returns either an ACK or NACK.
|
||||
|
||||
### Command Structure
|
||||
A zephyr app for a hexapod project.
|
||||
|
||||
```c
|
||||
struct command_message_t {
|
||||
uint8_t prefix; // 0x69
|
||||
uint8_t length;
|
||||
uint8_t id;
|
||||
uint8_t command;
|
||||
uint8_t crc;
|
||||
uint8_t data[160];
|
||||
} __attribute__((packed));
|
||||
/*
|
||||
|
||||
(1) (6)
|
||||
\ /
|
||||
\ /
|
||||
\ /
|
||||
*---(F)---*
|
||||
/ \
|
||||
/ \
|
||||
/ \
|
||||
(2)---* o *---(5)
|
||||
\ /
|
||||
\ /
|
||||
\ /
|
||||
*---(B)---*
|
||||
/ \
|
||||
/ \
|
||||
/ \
|
||||
(3) (4)
|
||||
|
||||
*/
|
||||
```
|
||||
|
||||
### CRC Calculation Function
|
||||
## Project overview
|
||||
From [../pins.drawio](../pins.drawio)
|
||||

|
||||
|
||||
```c
|
||||
uint8_t calculate_crc(struct command_message_t *msg) {
|
||||
uint32_t sum = 0;
|
||||
uint8_t crc = 0;
|
||||
## Hardware
|
||||
This project uses custom open source RP2350B board developed in [Servo2350](https://git.aintmina.org/aintgit/servo2350).
|
||||
|
||||
uint8_t *byte_ptr = (uint8_t *)msg;
|
||||
Schematics can be found in [boards/arm/servo2350/docs/Servo2350.pdf](boards/arm/servo2350/docs/Servo2350.pdf).
|
||||
|
||||
for (int i = 0; i < (sizeof(struct command_message_t) - sizeof(msg->data) + msg->length) - 1; i++) {
|
||||
sum += byte_ptr[i];
|
||||
}
|
||||
## Zephyr environment setup
|
||||
See [SETUP.md](SETUP.md)
|
||||
|
||||
crc = 0x100 - (sum & 0xff);
|
||||
|
||||
return crc;
|
||||
}
|
||||
```
|
||||
|
||||
### Python test script (AI generated)
|
||||
|
||||
**Command Usage:**
|
||||
|
||||
```bash
|
||||
python3 scripts/led_blink.py
|
||||
```
|
||||
|
||||
This script sends LED toggle commands to the device connected via USB.
|
||||
## Communication
|
||||
See [COMMANDS.md](COMMANDS.md)
|
||||
Reference in New Issue
Block a user