-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
283 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
board: | ||
- esp32dev | ||
- adafruit_feather_m0 | ||
- teensylc | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Pano Controller Configuration File for ESP32 board | ||
* https://github.com/espressif/arduino-esp32/blob/master/docs/esp32_pinmap.png | ||
* https://desire.giesecke.tk/index.php/2018/07/06/reserved-gpios/ | ||
*/ | ||
#include <Arduino.h> | ||
|
||
/* SPI (for display) | ||
SPI2 and SPI3 are general purpose SPI controllers, sometimes referred to as HSPI and VSPI | ||
SDA = IO 23 | ||
SCLK = IO 18 | ||
D/C = IO 21 | ||
RST = IO 22 | ||
CS = IO 5 | ||
*/ | ||
|
||
// Camera shutter controls | ||
#define CAMERA_FOCUS GPIO_NUM_16 | ||
#define CAMERA_SHUTTER GPIO_NUM_17 | ||
|
||
// Battery measurement pin R1/R2 | ||
#define BATTERY GPIO_NUM_34 //34 # ADC1 CH0 | ||
|
||
// MPU (accel/gyro) | ||
// GPIO_NUM_21 I2C SDA | ||
// GPIO_NUM_22 I2C SCL | ||
#define MPU_INT GPIO_NUM_2 | ||
#define MPU_VCC GPIO_NUM_4 | ||
|
||
// Future devices | ||
//#define COMPASS_DRDY xx | ||
|
||
// Stepper drivers control | ||
#define DIR GPIO_NUM_27 | ||
#define VERT_STEP GPIO_NUM_25 | ||
#define HORIZ_STEP GPIO_NUM_26 | ||
|
||
// this should be hooked up to nENABLE on both drivers | ||
#define nENABLE GPIO_NUM_14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#if defined(ESP32) | ||
|
||
#include "ble_esp32.h" | ||
|
||
// Nordic UART uuids | ||
#define UART_SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" | ||
#define UART_RX_CHAR_UUID "6E400002-B5A3-F393-E0A9-E50E24DCCA9E" | ||
#define UART_TX_CHAR_UUID "6E400003-B5A3-F393-E0A9-E50E24DCCA9E" | ||
#define PANO_SERVICE_UUID (uint16_t)2017 | ||
|
||
// How many bytes we can send at once | ||
#define BLOCK_SIZE 128 | ||
|
||
void Bluetooth::begin(const char *name) { | ||
BLEDevice::init(name); | ||
|
||
pServer = BLEDevice::createServer(); | ||
pServer->setCallbacks(&serverCallbacks); | ||
|
||
pServer->createService(PANO_SERVICE_UUID)->start(); | ||
|
||
BLEService *pService = pServer->createService(UART_SERVICE_UUID); | ||
rx = pService->createCharacteristic(UART_RX_CHAR_UUID, BLECharacteristic::PROPERTY_WRITE); | ||
rx->setCallbacks(&rxCallbacks); | ||
|
||
tx = pService->createCharacteristic(UART_TX_CHAR_UUID, BLECharacteristic::PROPERTY_NOTIFY); | ||
tx->addDescriptor(new BLE2902()); // 0x2902: org.bluetooth.descriptor.gatt.client_characteristic_configuration | ||
|
||
pService->start(); | ||
|
||
pServer->startAdvertising(); | ||
} | ||
|
||
bool Bluetooth::isConnected(void) { | ||
return ((ServerCallbacks *)&serverCallbacks)->isConnected(); // FIXME: temporary | ||
} | ||
|
||
void RXCallbacks::onWrite(BLECharacteristic *pCharacteristic) { | ||
std::string val = pCharacteristic->getValue(); | ||
int len = val.length(); | ||
if (len > 0 && abs(writeAt - readAt) < len ) { | ||
if (writeAt + len < buf + FIFO_SIZE) { // no wrap | ||
std::copy(val.begin(), val.end(), writeAt); | ||
writeAt += len; | ||
} else { | ||
int wrapLen = buf + FIFO_SIZE - writeAt; | ||
std::copy(val.begin(), val.begin() + wrapLen, writeAt); | ||
std::copy(val.begin() + wrapLen, val.end(), buf); | ||
writeAt = buf + len - wrapLen; | ||
} | ||
} | ||
}; | ||
|
||
int RXCallbacks::read(void) { | ||
return available() ? (int)(*readAt++) : EOF; | ||
} | ||
|
||
int RXCallbacks::peek(void) { | ||
return available() ? (int)(*readAt) : EOF; | ||
} | ||
|
||
void RXCallbacks::flush(void) { | ||
writeAt = readAt = buf; | ||
} | ||
|
||
/* | ||
* Implement Stream interface | ||
*/ | ||
size_t Bluetooth::write(uint8_t c) { | ||
if (isConnected()) { | ||
tx->setValue(&c, 1); | ||
tx->notify(); | ||
ets_delay_us(10000); // bluetooth stack will go into congestion, if too many packets are sent | ||
return 1; | ||
} | ||
return 0; | ||
}; | ||
|
||
size_t Bluetooth::write(const uint8_t *buf, size_t size) { | ||
size_t remain = size; | ||
while (isConnected() && remain > 0) { | ||
if (remain > BLOCK_SIZE){ | ||
tx->setValue((uint8_t*)buf, BLOCK_SIZE); | ||
remain -= BLOCK_SIZE; | ||
buf += BLOCK_SIZE; | ||
} else { | ||
tx->setValue((uint8_t*)buf, remain); | ||
remain = 0; | ||
} | ||
tx->notify(); | ||
ets_delay_us(10000); | ||
} | ||
return size - remain; | ||
} | ||
|
||
int Bluetooth::available(void) { | ||
return rxCallbacks.available(); | ||
}; | ||
int Bluetooth::read(void) { | ||
return rxCallbacks.read(); | ||
}; | ||
int Bluetooth::peek(void) { | ||
return rxCallbacks.peek(); | ||
}; | ||
void Bluetooth::flush(void) { | ||
rxCallbacks.flush(); | ||
}; | ||
|
||
#endif // defined(ESP32) |
Oops, something went wrong.