Files
esp-air-monitor/components/pms5003/pms5003.c
2023-11-01 21:56:12 +00:00

41 lines
1.2 KiB
C

#include "pms5003.h"
#include "driver/gpio.h"
#include "driver/uart.h"
#include "hal/gpio_types.h"
#include "hal/uart_types.h"
#define START_CHAR_1 0x42
#define START_CHAR_2 0x4d
#define DEFAULT_BAUD 9600
static const char* TAG = "PMS5003";
pms5003_err pms5003_init() {
const uart_port_t uart_num = CONFIG_PMS5003_UART_PORT;
uart_set_pin(uart_num, CONFIG_PMS5003_UART_TX, CONFIG_PMS5003_UART_RX, -1, -1);
uart_config_t uart_config = {
.baud_rate = DEFAULT_BAUD,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.rx_flow_ctrl_thresh = 122, // No idea what this does - it's a default I found somewhere
};
gpio_set_direction(CONFIG_PMS5003_SET_GPIO, GPIO_MODE_DEF_OUTPUT);
// Datasheet has 10k pull-up
gpio_set_pull_mode(CONFIG_PMS5003_SET_GPIO, GPIO_PULLUP_ONLY);
return PMS5003_OK;
}
pms5003_err pms5003_read(void) {
// uart_read_bytes
// 2 Start Bytes
// 2 Frame Length Bytes
// 26 (1 -> 13 pairs) Data Bytes (with nothing in 13)
// 2 Check Bytes - I think just add the low bits???
// 32 Bytes Total
return PMS5003_OK;
}