Skip to content

Commit

Permalink
RA4M1: misc. improvements and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Mar 18, 2024
1 parent 8c9ceda commit 69ae24c
Show file tree
Hide file tree
Showing 20 changed files with 5,909 additions and 113 deletions.
202 changes: 91 additions & 111 deletions software/firmware/source/SoftRF/src/platform/RA4M1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,48 +80,12 @@ const char *RA4M1_Device_Manufacturer = SOFTRF_IDENT;
const char *RA4M1_Device_Model = "Academy Edition";
const uint16_t RA4M1_Device_Version = SOFTRF_USB_FW_VERSION;

#if defined(USE_USB_HOST)

#include <cdcacm.h>
#include <usbhub.h>

class ACMAsyncOper : public CDCAsyncOper
{
public:
uint8_t OnInit(ACM *pacm);
};

uint8_t ACMAsyncOper::OnInit(ACM *pacm)
{
uint8_t rcode;
// Set DTR = 1 RTS=1
rcode = pacm->SetControlLineState(3);

if (rcode)
{
ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
return rcode;
}

LINE_CODING lc;
lc.dwDTERate = 115200;
lc.bCharFormat = 0;
lc.bParityType = 0;
lc.bDataBits = 8;

rcode = pacm->SetLineCoding(&lc);

if (rcode)
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);

return rcode;
}

USBHost UsbH;
ACMAsyncOper AsyncOper;
ACM AcmSerial(&UsbH, &AsyncOper);
#if defined(ARDUINO_UNOR4_WIFI)
#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"

#endif /* USE_USB_HOST */
ArduinoLEDMatrix matrix;
#endif /* ARDUINO_UNOR4_WIFI */

static void RA4M1_setup()
{
Expand Down Expand Up @@ -169,15 +133,26 @@ static void RA4M1_setup()
USBDevice.setDeviceVersion(RA4M1_Device_Version);
#endif /* USE_TINYUSB */

#if defined(USE_USB_HOST)
UsbH.Init();
#endif /* USE_USB_HOST */

Serial.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS);

#if defined(USBCON)
for (int i=0; i < 20; i++) {if (Serial) break; else delay(100);}
#endif

#if defined(ARDUINO_UNOR4_WIFI)
matrix.begin();
matrix.beginDraw();

matrix.stroke(0xFFFFFFFF);
matrix.textScrollSpeed(50);

const char text[] = " " SOFTRF_IDENT;
matrix.textFont(Font_5x7);
matrix.beginText(0, 1, 0xFFFFFF);
matrix.println(text);
matrix.endText(SCROLL_LEFT);
matrix.endDraw();
#endif /* ARDUINO_UNOR4_WIFI */
}

static void RA4M1_post_init()
Expand Down Expand Up @@ -213,28 +188,34 @@ static void RA4M1_post_init()
Serial.print(F("NMEA - "));
switch (settings->nmea_out)
{
case NMEA_UART : Serial.println(F("UART")); break;
case NMEA_USB : Serial.println(F("USB CDC")); break;
case NMEA_UART : Serial.println(F("UART")); break;
case NMEA_USB : Serial.println(F("USB CDC")); break;
case NMEA_UDP : Serial.println(F("UDP")); break;
case NMEA_TCP : Serial.println(F("TCP")); break;
case NMEA_BLUETOOTH : Serial.println(F("Bluetooth")); break;
case NMEA_OFF :
default : Serial.println(F("NULL")); break;
default : Serial.println(F("NULL")); break;
}

Serial.print(F("GDL90 - "));
switch (settings->gdl90)
{
case GDL90_UART : Serial.println(F("UART")); break;
case GDL90_USB : Serial.println(F("USB CDC")); break;
case GDL90_UART : Serial.println(F("UART")); break;
case GDL90_USB : Serial.println(F("USB CDC")); break;
case GDL90_UDP : Serial.println(F("UDP")); break;
case GDL90_BLUETOOTH : Serial.println(F("Bluetooth")); break;
case GDL90_OFF :
default : Serial.println(F("NULL")); break;
default : Serial.println(F("NULL")); break;
}

Serial.print(F("D1090 - "));
switch (settings->d1090)
{
case D1090_UART : Serial.println(F("UART")); break;
case D1090_USB : Serial.println(F("USB CDC")); break;
case D1090_UART : Serial.println(F("UART")); break;
case D1090_USB : Serial.println(F("USB CDC")); break;
case D1090_BLUETOOTH : Serial.println(F("Bluetooth")); break;
case D1090_OFF :
default : Serial.println(F("NULL")); break;
default : Serial.println(F("NULL")); break;
}

Serial.println();
Expand Down Expand Up @@ -288,6 +269,19 @@ static void RA4M1_loop()
}
}
#endif /* SOC_GPIO_RADIO_LED_RX */

#if SOC_GPIO_PIN_GNSS_PPS != SOC_UNUSED_PIN
static bool prev_PPS_state = LOW;

if (digitalPinToInterrupt(SOC_GPIO_PIN_GNSS_PPS) == NOT_AN_INTERRUPT) {
bool PPS_state = digitalRead(SOC_GPIO_PIN_GNSS_PPS);

if (PPS_state == HIGH && prev_PPS_state == LOW) {
PPS_TimeMarker = millis();
}
prev_PPS_state = PPS_state;
}
#endif
}

static void RA4M1_fini(int reason)
Expand Down Expand Up @@ -326,7 +320,7 @@ static String RA4M1_getResetInfo()
{
switch (reset_info.reason)
{
default : return F("No reset information available");
default : return F("No reset information available");
}
}

Expand Down Expand Up @@ -455,11 +449,7 @@ static void RA4M1_EEPROM_extension(int cmd)

static void RA4M1_SPI_begin()
{
#if USE_ISP_PORT
SPI.begin();
#else
// SPI1.begin();
#endif
}

static void RA4M1_swSer_begin(unsigned long baud)
Expand Down Expand Up @@ -675,7 +665,45 @@ static void RA4M1_Button_fini()
#endif /* SOC_GPIO_PIN_BUTTON != SOC_UNUSED_PIN */
}

#if !defined(ARDUINO_UNOR4_WIFI)
#if defined(ARDUINO_UNOR4_WIFI)

static void UNOR4W_Serial_setup() { }
static void UNOR4W_Serial_loop() { }
static void UNOR4W_Serial_fini() { }
static int UNOR4W_Serial_available() { return SerialOutput.available(); }
static int UNOR4W_Serial_read() { return SerialOutput.read(); }

static size_t UNOR4W_Serial_write(const uint8_t *buffer, size_t size)
{
/*
if (nl) {
if (buf[size-1] == '\r') {
SerialOutput.write(buf, size-1);
SerialOutput.write((byte *) "\r\n", 2);
} else {
SerialOutput.write(buf, size);
SerialOutput.write('\n');
}
} else {
SerialOutput.write(buf, size);
}
*/

return SerialOutput.write(buffer, size);
}

IODev_ops_t UNOR4W_Serial_ops = {
"UNOR4W Serial",
UNOR4W_Serial_setup,
UNOR4W_Serial_loop,
UNOR4W_Serial_fini,
UNOR4W_Serial_available,
UNOR4W_Serial_read,
UNOR4W_Serial_write
};

#else

static void RA4M1_USB_setup()
{
if (USBSerial && USBSerial != Serial) {
Expand All @@ -699,55 +727,7 @@ RingBufferN<USB_RX_FIFO_SIZE> USB_RX_FIFO = RingBufferN<USB_RX_FIFO_SIZE>();

static void RA4M1_USB_loop()
{
#if defined(USE_USB_HOST)

UsbH.Task();

if (AcmSerial.isReady()) {
uint8_t rcode;
uint8_t data[USBD_CDC_IN_OUT_MAX_SIZE];
size_t size;

while ((size = USB_TX_FIFO.available()) != 0) {

if (size > sizeof(data)) {
size = sizeof(data);
}

for (size_t i=0; i < size; i++) {
data[i] = USB_TX_FIFO.read_char();
}

rcode = AcmSerial.SndData(size, data);
if (rcode) {
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
}
}

uint16_t rcvd = sizeof(data);
rcode = AcmSerial.RcvData(&rcvd, data);
if (rcode && rcode != USB_ERRORFLOW) {
ErrorMessage<uint8_t>(PSTR("RcvData"), rcode);
} else {
if( rcvd ) {
#if 1
SerialOutput.write(data, rcvd);
#else
size_t written;
for (written=0; written < rcvd; written++) {
if (!USB_RX_FIFO.isFull()) {
USB_RX_FIFO.store_char(data[written]);
} else {
break;
}
}
#endif
}
}
}

#elif !defined(USE_TINYUSB)
#if !defined(USE_TINYUSB)

uint8_t buf[USBD_CDC_IN_OUT_MAX_SIZE];
size_t size;
Expand Down Expand Up @@ -783,7 +763,6 @@ static void RA4M1_USB_loop()
break;
}
}

#endif /* USE_TINYUSB */
}

Expand Down Expand Up @@ -893,10 +872,11 @@ const SoC_ops_t RA4M1_ops = {
#endif /* EXCLUDE_BLUETOOTH */
#if !defined(ARDUINO_UNOR4_WIFI)
&RA4M1_USBSerial_ops,
NULL,
#else
NULL,
&UNOR4W_Serial_ops,
#endif /* ARDUINO_UNOR4_WIFI */
NULL,
RA4M1_Display_setup,
RA4M1_Display_loop,
RA4M1_Display_fini,
Expand Down
4 changes: 4 additions & 0 deletions software/firmware/source/SoftRF/src/platform/RA4M1.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ struct rst_info {

#define SOC_GPIO_PIN_LED SOC_UNUSED_PIN
#define SOC_GPIO_PIN_GNSS_PPS PIN_A3
#define NOT_AN_INTERRUPT SOC_GPIO_PIN_GNSS_PPS
#define SOC_GPIO_PIN_BATTERY PIN_A0
#define SOC_GPIO_PIN_BUTTON SOC_UNUSED_PIN

Expand Down Expand Up @@ -175,6 +176,9 @@ struct rst_info {
#define EXCLUDE_LED_RING // - kb
#define EXCLUDE_SOUND

//#define USE_BASICMAC
//#define EXCLUDE_SX1276 // - 3 kb

#define USE_OLED // kb
#define EXCLUDE_OLED_049
//#define EXCLUDE_OLED_BARO_PAGE
Expand Down
37 changes: 37 additions & 0 deletions software/firmware/source/libraries/ArduinoGraphics/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
:repository-owner: arduino-libraries
:repository-name: ArduinoGraphics

= {repository-name} Library for Arduino =

image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"]
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"]
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"]

Core graphics library for Arduino. Based on the Processing API.

For more information about this library please visit us at https://www.arduino.cc/en/Reference/ArduinoGraphics

== License ==

Copyright (c) 2019 Arduino SA. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

== How-to generate bitmaps from the fonts ==
[source,bash]
----
cd extra
./generate_font.py 5x7.bdf Font_5x7.c Font_5x7
----
Loading

0 comments on commit 69ae24c

Please sign in to comment.