Skip to content

Commit

Permalink
v0.7
Browse files Browse the repository at this point in the history
Added serial mouse, optimized core and task distribution
  • Loading branch information
Hamberthm authored Sep 2, 2024
1 parent 4b9a214 commit d91fd29
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/esp32-ps2dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace esp32_ps2dev
const uint32_t BYTE_INTERVAL_MICROS = 500; // in v0.4 was OK: 500, change if not working and you know what you're doing.
const int PACKET_QUEUE_LENGTH = 20;
const UBaseType_t DEFAULT_TASK_PRIORITY = 10;
const BaseType_t DEFAULT_TASK_CORE = APP_CPU_NUM;
//const BaseType_t DEFAULT_TASK_CORE = APP_CPU_NUM;
const BaseType_t DEFAULT_TASK_CORE = 0;
const BaseType_t DEFAULT_TASK_CORE_MOUSE = 1;
// The device should check for "HOST_REQUEST_TO_SEND" at a interval not exceeding 10 milliseconds.
const uint32_t INTERVAL_CHECKING_HOST_SEND_REQUEST_MILLIS = 9;
const uint32_t MOUSE_CLICK_PRESSING_DURATION_MILLIS = 100;
Expand All @@ -54,7 +56,7 @@ namespace esp32_ps2dev
};

void config(UBaseType_t task_priority, BaseType_t task_core);
void begin();
void begin(BaseType_t core);
int write(unsigned char data);
int write_wait_idle(uint8_t data, uint64_t timeout_micros = 1500);
int read(unsigned char *data, uint64_t timeout_ms = 0);
Expand Down
37 changes: 37 additions & 0 deletions include/serial_mouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "esp_timer.h"

class serialMouse
{
public:
struct Data
{
uint8_t buttons;
int xMovement;
int yMovement;
} report_data, report_buffer;

void setup(int rtsPin, int rxPin);
void serialMove(uint8_t buttons, int16_t mouseX, int16_t mouseY);
static void initSerialPort();
static TaskHandle_t handle_reset_watchdog;
static TaskHandle_t handle_serial_daemon;
static bool resetReceived; // Host system issued a reset command via RTS pin
static int RS232_RTS;
static int RS232_RX;
static void sendToSerial(const serialMouse::Data &data);

private:
static constexpr char const *TAG = "serial_mouse";
static unsigned long IRAM_ATTR micros();
static void IRAM_ATTR delayMicroseconds(uint32_t us);
static void sendSerialBit(int data);
static void sendSerialByte(uint8_t data);
};

0 comments on commit d91fd29

Please sign in to comment.