NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
serial_msp.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 
57 // Each MSP port requires state and a receive buffer, revisit this default if someone needs more than 2 MSP ports.
58 #define MAX_MSP_PORT_COUNT 2
59 
60 #include "drivers/serial.h"
61 
62 typedef enum {
70 } mspState_e;
71 
72 #define MSP_PORT_INBUF_SIZE 64
73 #define MSP_PORT_OUTBUF_SIZE 256
74 
76  serialPort_t *port; // NULL when port unused.
78  uint8_t offset;
79  uint8_t dataSize;
80  uint8_t cmdMSP;
82 };
83 
84 struct ninja;
85 struct msp;
86 
87 struct serial_msp {
89  const struct config *config;
90  struct msp *msp;
91 };
92 
93 // TODO: look into the dependency here. serial_msp is pointing to msp parser which processes commands received from multiple msp ports managed by single serial_msp object.
94 
95 void serial_msp_init(struct serial_msp *self, const struct config *config, struct msp *msp);
96 void serial_msp_process(struct serial_msp *self, struct ninja *ninja);
97 //void serial_msp_alloc_ports(struct serial_msp *self);
98 void serial_msp_release_port(struct serial_msp *self, serialPort_t *serialPort);
const struct config * config
Definition: serial_msp.h:89
Definition: serial_msp.h:65
Definition: config.h:81
struct serial_msp_port ports[MAX_MSP_PORT_COUNT]
Definition: serial_msp.h:88
Definition: ninja.h:40
mspState_e c_state
Definition: serial_msp.h:77
uint8_t offset
Definition: serial_msp.h:78
Definition: serial_msp.h:63
Definition: serial_msp.h:87
void serial_msp_release_port(struct serial_msp *self, serialPort_t *serialPort)
Definition: serial_msp.c:85
#define MSP_PORT_INBUF_SIZE
Definition: serial_msp.h:72
mspState_e
Definition: serial_msp.h:62
Definition: serial_msp.h:69
Definition: serial_msp.h:68
void serial_msp_init(struct serial_msp *self, const struct config *config, struct msp *msp)
Definition: serial_msp.c:96
struct msp * msp
Definition: serial_msp.h:90
uint8_t inBuf[MSP_PORT_INBUF_SIZE]
Definition: serial_msp.h:81
Definition: msp.h:28
Definition: serial_msp.h:67
Definition: serial_msp.h:64
uint8_t cmdMSP
Definition: serial_msp.h:80
serialPort_t * port
Definition: serial_msp.h:76
void serial_msp_process(struct serial_msp *self, struct ninja *ninja)
Definition: serial_msp.c:208
#define MAX_MSP_PORT_COUNT
Definition: serial_msp.h:58
Definition: serial_msp.h:66
Definition: serial_msp.h:75
Definition: serial.h:43
uint8_t dataSize
Definition: serial_msp.h:79