diff --git a/Makefile b/Makefile index abb9347..b2f9b0b 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -DBAUD=$(BAUD) CFLAGS += -DRFM=$(RFM) -DLORA=$(LORA) CFLAGS += -DDISPLAY_WIDTH=$(DISPLAY_WIDTH) -DDISPLAY_HEIGHT=$(DISPLAY_HEIGHT) CFLAGS += -DINVERT=$(INVERT) -DBGR=$(BGR) -DHFLIP=$(HFLIP) -DVFLIP=$(VFLIP) -CFLAGS += -O2 -I. +CFLAGS += -O2 -I. -I../ CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CFLAGS += -Wall -Wstrict-prototypes CFLAGS += -g -ggdb @@ -57,13 +57,13 @@ CFLAGS += -std=gnu99 TARGET = $(strip $(basename $(MAIN))) SRC += $(TARGET).c -SRC += librfm$(RFM).a libtft.a libsdc.a +SRC += ../librfm$(RFM)/librfm$(RFM).a ../libtft/libtft.a ../libsdc/libsdc.a OBJ = $(SRC:.c=.o) OBJ = $(SRC:.S=.o) -$(TARGET).elf: dejavu.h i2c.h mcp9808.h pins.h spi.h types.h unifont.h usart.h \ - utils.h librfm$(RFM).h libtft.h libsdc.h Makefile +$(TARGET).elf: dejavu.h i2c.h mcp9808.h pins.h spi.h types.h usart.h \ + utils.h Makefile all: $(TARGET).hex diff --git a/avrrfm.c b/avrrfm.c index e4b5681..b21aa1b 100644 --- a/avrrfm.c +++ b/avrrfm.c @@ -27,12 +27,17 @@ #include "usart.h" #include "spi.h" #include "utils.h" -#include "librfm95.h" -#include "libtft.h" -#include "libsdc.h" #include "mcp9808.h" #include "dejavu.h" -#include "unifont.h" +#if RFM == 69 + #include "librfm69/librfm69.h" +#endif +#if RFM == 95 + #include "librfm95/librfm95.h" +#endif +#include "libtft/libtft.h" +#include "libtft/unifont.h" +#include "libsdc/libsdc.h" #define TRANSMIT_INT 300 // seconds diff --git a/bitmaps.c b/bitmaps.c index 68bb7a7..f94565c 100644 --- a/bitmaps.c +++ b/bitmaps.c @@ -5,7 +5,7 @@ * Created on 06/07/2023, 23:28 */ -#include "font.h" +#include "libtft/font.h" const __flash uint8_t TUX_DATA[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/dejavu.h b/dejavu.h index a4b45c4..c3fb24b 100644 --- a/dejavu.h +++ b/dejavu.h @@ -9,7 +9,7 @@ #ifndef DEJAVU_H #define DEJAVU_H -#include "font.h" +#include "libtft/font.h" /** * DejaVu font. diff --git a/font.h b/font.h deleted file mode 100644 index 6a10326..0000000 --- a/font.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * File: font.h - * Author: torsten.roemer@luniks.net - * - * Created on 24. April 2023, 21:21 - */ - -#ifndef FONT_H -#define FONT_H - -#include -#include "types.h" - -/* Colorspaces */ -#define SPACE_MONO1 1 -#define SPACE_GREY4 4 -#define SPACE_RGB16 16 - -/** - * A bitmap with its width and height, and data. - */ -typedef struct { - /** Width of the bitmap. */ - const width_t width; - /** Height of the bitmap. */ - const height_t height; - /** Color space of the bitmap. */ - const space_t space; - /** The actual bitmap. */ - const __flash uint8_t *bitmap; -} Bitmap; - -/** - * Available bitmaps. - */ -extern const __flash Bitmap bitmaps[]; - -/** - * A glyph with its pseudo UTF-8 code point, width and bitmap. - */ -typedef struct { - /** Pseudo UTF-8 code point of the glyph. */ - const code_t code; - /** Width of the glyph. */ - const width_t width; - /** Bitmap of the glyph. */ - const __flash uint8_t *bitmap; -} Glyph; - -/** - * Fonts available here. Since the height is the same for all glyphs, - * it is stored in the font instead of redundantly in each glyph. - */ -typedef struct { - /** Glyphs of this font. */ - const __flash Glyph *glyphs; - /** Number of glyphs of this font. */ - const length_t length; - /** Height of (the glyphs of) this font. */ - const height_t height; - /** Color space of the glyph bitmap. */ - const space_t space; -} Font; - -/** - * Returns the flash address of the glyph at the given pseudo UTF-8 code - * point, i.e. 0x00f6 for U+00F6 from the given font. - * If there is no glyph for that code point, a question mark is returned. - * @param font - * @param code - * @return Glyph - */ -const __flash Glyph* getGlyphAddress(const __flash Font *font, code_t code); - -#endif /* FONT_H */ diff --git a/hack.h b/hack.h deleted file mode 100644 index 80cb449..0000000 --- a/hack.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * File: hack.h - * Author: torsten.roemer@luniks.net - * - * The work in the Hack project is Copyright 2018 Source Foundry Authors and - * licensed under the MIT License. - * The work in the DejaVu project was committed to the public domain. - * Bitstream Vera Sans Mono Copyright 2003 Bitstream Inc. and licensed under - * the Bitstream Vera License with Reserved Font Names "Bitstream" and "Vera". - * - * A subset of glyphs in the Hack font as 8x16 bitmaps in 4-Bit greyscale - * with antialiasing. - * - * Created on 16. November 2023, 17:25 - */ - -#ifndef HACK_H -#define HACK_H - -#include "font.h" - -/** - * Hack font. - */ -extern const __flash Font hackFont; - -#endif /* HACK_H */ - diff --git a/librfm69.a b/librfm69.a deleted file mode 100644 index badc4df..0000000 Binary files a/librfm69.a and /dev/null differ diff --git a/librfm69.h b/librfm69.h deleted file mode 100644 index c79332f..0000000 --- a/librfm69.h +++ /dev/null @@ -1,227 +0,0 @@ -/* - * File: librfm69.h - * Author: torsten.roemer@luniks.net - * - * Created on 23. März 2025, 23:04 - */ - -#ifndef LIBRFM69_H -#define LIBRFM69_H - -#include -#include -#include - -#define RFM_FIFO 0x00 -#define RFM_OP_MODE 0x01 -#define RFM_DATA_MOD 0x02 -#define RFM_BITRATE_MSB 0x03 -#define RFM_BITRATE_LSB 0x04 -#define RFM_FDEV_MSB 0x05 -#define RFM_FDEV_LSB 0x06 -#define RFM_FRF_MSB 0x07 -#define RFM_FRF_MID 0x08 -#define RFM_FRF_LSB 0x09 -#define RFM_OSC1 0x0a -#define RFM_PA_LEVEL 0x11 -#define RFM_LNA 0x18 -#define RFM_RX_BW 0x19 -#define RFM_AFC_BW 0x1a -#define RFM_AFC_FEI 0x1e -#define RFM_RSSI_CONFIG 0x23 -#define RFM_RSSI_VALUE 0x24 -#define RFM_DIO_MAP1 0x25 -#define RFM_DIO_MAP2 0x26 -#define RFM_IRQ_FLAGS1 0x27 -#define RFM_RSSI_THRESH 0x29 -#define RFM_RX_TO_RSSI 0x2a -#define RFM_RX_TO_PRDY 0x2b -#define RFM_PREAMB_MSB 0x2c -#define RFM_PREAMB_LSB 0x2d -#define RFM_IRQ_FLAGS2 0x28 -#define RFM_SYNC_CONF 0x2e -#define RFM_SYNC_VAL1 0x2f -#define RFM_SYNC_VAL2 0x30 -#define RFM_SYNC_VAL3 0x31 -#define RFM_SYNC_VAL4 0x32 -#define RFM_SYNC_VAL5 0x33 -#define RFM_SYNC_VAL6 0x34 -#define RFM_SYNC_VAL7 0x35 -#define RFM_SYNC_VAL8 0x36 -#define RFM_PCK_CFG1 0x37 -#define RFM_PAYLOAD_LEN 0x38 -#define RFM_NODE_ADDR 0x39 -#define RFM_CAST_ADDR 0x3a -#define RFM_AUTO_MODES 0x3b -#define RFM_FIFO_THRESH 0x3c -#define RFM_PCK_CFG2 0x3d -#define RFM_TEST_LNA 0x58 -#define RFM_TEST_PA1 0x5a -#define RFM_TEST_PA2 0x5c -#define RFM_TEST_DAGC 0x6f -#define RFM_TEST_AFC 0x71 - -#define RFM_MODE_SLEEP 0x00 -#define RFM_MODE_STDBY 0x04 -#define RFM_MODE_FS 0x08 -#define RFM_MODE_TX 0x0c -#define RFM_MODE_RX 0x10 -#define RFM_MASK_MODE 0x1c - -#define RFM_F_STEP 61035 - -#define RFM_DBM_MIN -2 -#define RFM_DBM_MAX 13 -#define RFM_PA_MIN 16 -#define RFM_PA_MAX 31 -#define RFM_PA_OFF 14 - -#define RFM_MSG_SIZE 63 - -/** - * Flags for "payload ready" event. - */ -typedef struct { - bool ready; - bool crc; - uint8_t rssi; -} PayloadFlags; - -/** - * F_CPU dependent delay of 5 milliseconds. - * _delay_ms(5); - */ -void _rfmDelay5(void); - -/** - * Turns the radio on by pulling its reset pin LOW. - * PORTB &= ~(1 << PB0); - */ -void _rfmOn(void); - -/** - * Selects the radio to talk to via SPI. - * PORTB &= ~(1 << PB1); - */ -void _rfmSel(void); - -/** - * Deselects the radio to talk to via SPI. - * PORTB |= (1 << PB1); - */ -void _rfmDes(void); - -/** - * SPI transmits/receives given data/returns it. - * - * @param data - * @return data - */ -uint8_t _rfmTx(uint8_t data); - -/** - * Initializes the radio module with the given carrier frequency in kilohertz - * and node and brodcast address. Returns true on success, false otherwise. - * - * @param freq carrier frequency - * @param node address - * @param broadcast address - * @return success - */ -bool rfmInit(uint64_t freq, uint8_t node, uint8_t cast); - -/** - * Reads interrupt flags. Should be called when any interrupt occurs - * on DIO0 or DIO4. - */ -void rfmIrq(void); - -/** - * Sets the "Timeout" interrupt flag, allowing to "unlock" a possibly hanging - * wait for either "PayloadReady" or "Timeout" by the radio. - * Only used for RFM95 in FSK mode, can be a no-op here. - */ -void rfmTimeout(void); - -/** - * Shuts down the radio. - */ -void rfmSleep(void); - -/** - * Wakes up the radio. - */ -void rfmWake(void); - -/** - * Sets the node address. - * - * @param address - */ -void rfmSetNodeAddress(uint8_t address); - -/** - * Sets the output power to +2 to +17 dBm. - * Values outside that range are ignored. - * - * @param dBm ouput power - */ -void rfmSetOutputPower(int8_t dBm); - -/** - * Returns the current output power setting in dBm. - * - * @return ouput power - */ -int8_t rfmGetOutputPower(void); - -/** - * Sets the radio to receive mode and maps "PayloadReady" to DIO0 and enables - * or disables timeout. - * - * @param timeout enable timeout - */ -void rfmStartReceive(bool timeout); - -/** - * Returns true and puts the radio in standby mode if a "PayloadReady" - * interrupt arrived. - * - * @return flags - */ -PayloadFlags rfmPayloadReady(void); - -/** - * Sets the radio in standby mode, puts the payload into the given array - * with the given size, and returns the length of the payload. - * - * @param payload buffer for payload - * @param size of payload buffer - * @return payload bytes actually received - */ -size_t rfmReadPayload(uint8_t *payload, size_t size); - -/** - * Waits for "PayloadReady", puts the payload into the given array with the - * given size, enables or disables timeout, and returns the length of the - * payload, or 0 if a timeout occurred. - * - * @param payload buffer for payload - * @param size of payload buffer - * @param timeout enable timeout - * @return payload bytes actually received - */ -size_t rfmReceivePayload(uint8_t *payload, size_t size, bool timeout); - -/** - * Transmits up to 63 bytes of the given payload with the given node address. - * - * @param payload to be sent - * @param size of payload - * @param node address - * @return payload bytes actually sent - */ -size_t rfmTransmitPayload(uint8_t *payload, size_t size, uint8_t node); - -#endif /* LIBRFM69_H */ - diff --git a/librfm95.a b/librfm95.a deleted file mode 100644 index 66f61ae..0000000 Binary files a/librfm95.a and /dev/null differ diff --git a/librfm95.h b/librfm95.h deleted file mode 100644 index 2cc1d4b..0000000 --- a/librfm95.h +++ /dev/null @@ -1,320 +0,0 @@ -/* - * File: librfm95.h - * Author: torsten.roemer@luniks.net - * - * Created on 30. März 2025 - */ - -#ifndef LIBRFM95_H -#define LIBRFM95_H - -#include -#include -#include - -/* Registers shared by FSK and LoRa mode */ -#define RFM_FIFO 0x00 -#define RFM_OP_MODE 0x01 -#define RFM_FRF_MSB 0x06 -#define RFM_FRF_MID 0x07 -#define RFM_FRF_LSB 0x08 -#define RFM_PA_CONFIG 0x09 -#define RFM_PA_RAMP 0x0a -#define RFM_OCP 0x0b -#define RFM_LNA 0x0c -#define RFM_DIO_MAP1 0x40 -#define RFM_DIO_MAP2 0x41 -#define RFM_VERSION 0x42 - -/* FSK mode registers */ -#define RFM_FSK_BITRATE_MSB 0x02 -#define RFM_FSK_BITRATE_LSB 0x03 -#define RFM_FSK_FDEV_MSB 0x04 -#define RFM_FSK_FDEV_LSB 0x05 -#define RFM_FSK_PA_RAMP 0x0a -#define RFM_FSK_RX_CONFIG 0x0d -#define RFM_FSK_RSSI_CONFIG 0x0e -#define RFM_FSK_RSSI_COLLIS 0x0f -#define RFM_FSK_RSSI_THRESH 0x10 -#define RFM_FSK_RSSI_VALUE 0x11 -#define RFM_FSK_RX_BW 0x12 -#define RFM_FSK_AFC_BW 0x13 -#define RFM_FSK_AFC_FEI 0x1a -#define RFM_FSK_PREA_DETECT 0x1f -#define RFM_FSK_RX_TO_RSSI 0x20 -#define RFM_FSK_RX_TO_PREA 0x21 -#define RFM_FSK_RX_TO_SYNC 0x22 -#define RFM_FSK_RX_DELAY 0x23 -#define RFM_FSK_OSC 0x24 -#define RFM_FSK_PREA_MSB 0x25 -#define RFM_FSK_PREA_LSB 0x26 -#define RFM_FSK_SYNC_CONFIG 0x27 -#define RFM_FSK_SYNC_VAL1 0x28 -#define RFM_FSK_SYNC_VAL2 0x29 -#define RFM_FSK_SYNC_VAL3 0x2a -#define RFM_FSK_SYNC_VAL4 0x2b -#define RFM_FSK_SYNC_VAL5 0x2c -#define RFM_FSK_SYNC_VAL6 0x2d -#define RFM_FSK_SYNC_VAL7 0x2e -#define RFM_FSK_SYNC_VAL8 0x2f -#define RFM_FSK_PCK_CONFIG1 0x30 -#define RFM_FSK_PCK_CONFIG2 0x31 -#define RFM_FSK_PAYLOAD_LEN 0x32 -#define RFM_FSK_NODE_ADDR 0x33 -#define RFM_FSK_CAST_ADDR 0x34 -#define RFM_FSK_FIFO_THRESH 0x35 -#define RFM_FSK_IMAGE_CAL 0x3b -#define RFM_FSK_TEMP 0x3c -#define RFM_FSK_LOW_BAT 0x3d -#define RFM_FSK_IRQ_FLAGS1 0x3e -#define RFM_FSK_IRQ_FLAGS2 0x3f - -/* LoRa mode registers */ -#define RFM_LORA_FIFO_ADDR_PTR 0x0d -#define RFM_LORA_FIFO_TX_ADDR 0x0e -#define RFM_LORA_FIFO_RX_ADDR 0x0f -#define RFM_LORA_FIFO_CURR_ADDR 0x10 -#define RFM_LORA_IRQ_FLAGS_MASK 0x11 -#define RFM_LORA_IRQ_FLAGS 0x12 -#define RFM_LORA_RX_BYTES_NB 0x13 -#define RFM_LORA_RX_HDR_CNT_MSB 0x14 -#define RFM_LORA_RX_HDR_CNT_LSB 0x15 -#define RFM_LORA_RX_PCK_CNT_MSB 0x16 -#define RFM_LORA_RX_PCK_CNT_LSB 0x17 -#define RFM_LORA_MODEM_STAT 0x18 -#define RFM_LORA_PCK_SNR 0x19 -#define RFM_LORA_PCK_RSSI 0x1a -#define RFM_LORA_RSSI 0x1b -#define RFM_LORA_HOP_CHANNEL 0x1c -#define RFM_LORA_MODEM_CONFIG1 0x1d -#define RFM_LORA_MODEM_CONFIG2 0x1e -#define RFM_LORA_SYMB_TIMEO_LSB 0x1f -#define RFM_LORA_PREA_LEN_MSB 0x20 -#define RFM_LORA_PREA_LEN_LSB 0x21 -#define RFM_LORA_PAYLD_LEN 0x22 -#define RFM_LORA_PAYLD_MAX_LEN 0x23 -#define RFM_LORA_HOP_PERIOD 0x24 -#define RFM_LORA_FIFO_RX_B_ADDR 0x25 -#define RFM_LORA_MODEM_CONFIG3 0x26 - -/* Values shared by FSK and LoRa mode */ -#define RFM_MODE_SLEEP 0x00 -#define RFM_MODE_STDBY 0x01 -#define RFM_MODE_FS_TX 0x02 -#define RFM_MODE_TX 0x03 -#define RFM_MODE_FS_RX 0x04 -#define RFM_MODE_RX 0x05 // LoRa RXCONTINUOUS -#define RFM_MODE_RXSINGLE 0x06 // LoRa only -#define RFM_MODE_CAD 0x07 // LoRa only -#define RFM_MASK_MODE 0x07 - -#define RFM_F_STEP 61035 - -#define RFM_DBM_MIN 2 -#define RFM_DBM_MAX 17 -#define RFM_PA_MIN 0 -#define RFM_PA_MAX 15 -#define RFM_PA_OFF 2 - -/* FSK mode values */ -#define RFM_FSK_MSG_SIZE 63 - -/* LoRa mode values */ -// assuming 50/50 for Tx/Rx for now -#define RFM_LORA_MSG_SIZE 128 - -/** - * Flags for 'PayloadReady'/'RxDone' event. - */ -typedef struct { - bool ready; - bool crc; - uint8_t rssi; -} RxFlags; - -/** - * F_CPU dependent delay of 5 milliseconds. - * _delay_ms(5); - */ -void _rfmDelay5(void); - -/** - * Turns the radio on by pulling its reset pin high. - * PORTB |= (1 << PB0); - */ -void _rfmOn(void); - -/** - * Selects the radio to talk to via SPI. - * PORTB &= ~(1 << PB1); - */ -void _rfmSel(void); - -/** - * Deselects the radio to talk to via SPI. - * PORTB |= (1 << PB1); - */ -void _rfmDes(void); - -/** - * SPI transmits/receives given data/returns it. - * - * @param data - * @return data - */ -uint8_t _rfmTx(uint8_t data); - -/** - * Initializes the radio module in FSK or LoRa mode with the given carrier - * frequency in kilohertz and node and brodcast address. - * Returns true on success, false otherwise. - * - * @param freq carrier frequency - * @param node address - * @param broadcast address - * @param lora LoRa or FSK mode - * @return success - */ -bool rfmInit(uint64_t freq, uint8_t node, uint8_t cast, bool lora); - -/** - * Reads interrupt flags. Should be called when any interrupt occurs - * on DIO0 or DIO4 (FSK)/DIO1 (LoRa). - */ -void rfmIrq(void); - -/** - * Sets the "Timeout" interrupt flag, allowing to "unlock" a possibly hanging - * wait for either "PayloadReady" or "Timeout" by the radio in FSK mode, - * ignored in LoRa mode. - */ -void rfmTimeout(void); - -/** - * Shuts down the radio. - */ -void rfmSleep(void); - -/** - * Wakes up the radio. - */ -void rfmWake(void); - -/** - * Sets the node address. - * - * @param address - */ -void rfmSetNodeAddress(uint8_t address); - -/** - * Sets the output power to +2 to +17 dBm. - * Values outside that range are ignored. - * - * @param dBm ouput power - */ -void rfmSetOutputPower(int8_t dBm); - -/** - * Returns the current output power setting in dBm. - * - * @return ouput power - */ -int8_t rfmGetOutputPower(void); - -/** - * Sets the radio to receive mode and maps "PayloadReady" to DIO0 and enables - * or disables timeout. - * For FSK mode. - * - * @param timeout enable timeout - */ -void rfmStartReceive(bool timeout); - -/** - * Returns true and puts the radio in standby mode if a "PayloadReady" - * interrupt arrived. - * For FSK mode. - * - * @return flags - */ -RxFlags rfmPayloadReady(void); - -/** - * Sets the radio in standby mode, puts the payload into the given array - * with the given size, and returns the length of the payload. - * For FSK mode. - * - * @param payload buffer for payload - * @param size of payload buffer - * @return payload bytes actually received - */ -size_t rfmReadPayload(uint8_t *payload, size_t size); - -/** - * Waits for "PayloadReady", puts the payload into the given array with the - * given size, enables or disables timeout, and returns the length of the - * payload, or 0 if a timeout occurred. - * For FSK mode. - * - * @param payload buffer for payload - * @param size of payload buffer - * @param timeout enable timeout - * @return payload bytes actually received - */ -size_t rfmReceivePayload(uint8_t *payload, size_t size, bool timeout); - -/** - * Transmits up to 63 bytes of the given payload with the given node address. - * For FSK mode. - * - * @param payload to be sent - * @param size of payload - * @param node address - * @return payload bytes actually sent - */ -size_t rfmTransmitPayload(uint8_t *payload, size_t size, uint8_t node); - -/** - * Sets the radio in continous receive mode and maps "RxDone" to DIO0. - */ -void rfmLoRaStartRx(void); - -/** - * Returns true if a "RxDone" interrupt arrived. - * - * @return flags - */ -RxFlags rfmLoRaRxDone(void); - -/** - * Puts the received payload into the given array with the given size, - * and returns the length of the payload. - * - * @param payload buffer for payload - * @param size of payload buffer - * @return payload bytes actually received - */ -size_t rfmLoRaRxRead(uint8_t *payload, size_t size); - -/** - * Sets the radio in single receive mode, waits for "RxDone" with timeout, - * puts the payload into the given array with the given size, and returns - * the length of the payload, or 0 if a timeout occurred. - * - * @param payload buffer for payload - * @param size of payload buffer - * @return payload bytes actually received - */ -size_t rfmLoRaRx(uint8_t *payload, size_t size); - -/** - * Transmits up to 128 bytes of the given payload. - * - * @param payload to be sent - * @param size of payload - * @return payload bytes actually sent - */ -size_t rfmLoRaTx(uint8_t *payload, size_t size); - -#endif /* LIBRFM95_H */ diff --git a/libsdc.a b/libsdc.a deleted file mode 100644 index 4be8a3a..0000000 Binary files a/libsdc.a and /dev/null differ diff --git a/libsdc.h b/libsdc.h deleted file mode 100644 index acb45f6..0000000 --- a/libsdc.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * File: libsdc.h - * Author: torsten.roemer@luniks.net - * - * Created on 25.03.2025, 20:29 - */ - -#ifndef LIBSDC_H -#define LIBSDC_H - -#include -#include -#include - -#define CMD0 0 -#define CMD0_ARG 0x00000000 -#define CMD0_CRC 0x94 - -#define CMD8 8 -#define CMD8_ARG 0x0000001aa -#define CMD8_CRC 0x86 - -#define CMD12 12 -#define CMD12_ARG 0x00000000 -#define CMD12_CRC 0x60 - -#define CMD17 17 -#define CMD17_CRC 0x00 - -#define CMD18 18 -#define CMD18_CRC 0x00 - -#define CMD24 24 -#define CMD24_CRC 0x00 - -#define CMD55 55 -#define CMD55_ARG 0x00000000 -#define CMD55_CRC 0x64 - -#define CMD58 58 -#define CMD58_ARG 0x00000000 -#define CMD58_CRC 0xfc - -#define ACMD41 41 -#define ACMD41_ARG 0x40000000 -#define ACMD41_CRC 0x76 - -// TODO depends on SPI SCK frequency -#define SD_MAX_READ 50000 // SPI clock ticks in 100 ms -#define SD_MAX_WRITE 125000 // SPI clock ticks in 250 ms - -#define SD_BLOCK_SIZE 512 - -#define SD_CMD_ILLEGAL 2 - -#define SD_SUCCESS 0x00 -#define SD_START_BLOCK 0xfe - -/** - * Pointer to a function that takes an array of bytes - * and returns a boolean. - */ -typedef bool (*SDConsumer)(uint8_t*); - -/** - * F_CPU dependent delay of 10 milliseconds. - * _delay_ms(10); - * - * @param ms - */ -void _sdcDelay10(void); - -/** - * Selects the radio to talk to via SPI. - * PORTB &= ~(1 << PB1); - */ -void _sdcSel(void); - -/** - * Deselects the radio to talk to via SPI. - * PORTB |= (1 << PB1); - */ -void _sdcDes(void); - -/** - * SPI transmits/receives given data/returns it. - * - * @param data - * @return data - */ -uint8_t _sdcTx(uint8_t data); - -/** - * Initializes the SD Card and returns true on success, false otherwise. - * - * @return true on success, false otherwise - */ -bool sdcInit(void); - -/** - * Reads a single block of 512 bytes at the given address into - * the given buffer and returns true on success, false otherwise. - * - * @param address address in 512 byte units - * @param block 512 byte buffer - * @return success - */ -bool sdcReadSingleBlock(uint32_t address, uint8_t *block); - -/** - * Reads multiple blocks of 512 bytes starting at the given address - * and, for each block, passes the buffer to the given function. - * By returning false, the function can request to stop reading blocks. - * - * @param address - * @param consume - * @return success - */ -bool sdcReadMultiBlock(uint32_t address, SDConsumer consume); - -/** - * Writes a single block of 512 bytes starting at the given address - * from the given buffer and returns true on success, false otherwise. - * - * @param address address in 512 byte units - * @param block 512 byte buffer - * @return success - */ -bool sdcWriteSingleBlock(uint32_t address, uint8_t *block); - -#endif /* LIBSDC_H */ diff --git a/libtft.a b/libtft.a deleted file mode 100644 index b4ae5c9..0000000 Binary files a/libtft.a and /dev/null differ diff --git a/libtft.h b/libtft.h deleted file mode 100644 index b0c68b1..0000000 --- a/libtft.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - * File: tft.h - * Author: torsten.roemer@luniks.net - * - * Created on 6. November 2023, 18:45 - */ - -#ifndef LIBTFT_H -#define LIBTFT_H - -#include -#include -#include -#include -#include "font.h" - -#define SWRESET 0x01 -#define SLPIN 0x10 -#define SLPOUT 0x11 -#define NORON 0x13 -#define INVOFF 0x20 -#define INVON 0x21 -#define DISPON 0x29 -#define CASET 0x2a -#define RASET 0x2b -#define RAMWR 0x2c -#define MADCTL 0x36 -#define COLMOD 0x3a - -/** - * F_CPU dependent delay of 100 milliseconds. - * _delay_ms(100); - */ -void _tftDelay100(void); - -/** - * Selects the display to talk to via SPI. - * PORTB &= ~(1 << PB1); - */ -void _tftSel(void); - -/** - * Deselects the display to talk to via SPI. - * PORTB |= (1 << PB1); - */ -void _tftDes(void); - -/** - * Sets display to send a command. - * PORTB &= ~(1 << PB2); - */ -void _tftSetCmd(void); - -/** - * Sets display to send data. - * PORTB |= (1 << PB2); - */ -void _tftSetData(void); - -/** - * Does a hardware reset. - * PORTB &= ~(1 << PB3); - * _delay_ms(10); - * PORTB |= (1 << PB3); - */ -void _tftReset(void); - -/** - * SPI transmits/receives given data/returns it. - * - * @param data - * @return data - */ -uint8_t _tftTx(uint8_t data); - -/** - * Initializes the display. - * - * @param width display width - * @param height display height - * @param hflip horizontal flip - * @param vflip vertical flip - * @param bgr BGR or RGB - * @param invert invert display - */ -void tftInit(width_t width, height_t height, - bool hflip, bool vflip, - bool bgr, bool invert); - -/** - * Sets to write data to display RAM. - */ -void tftWriteStart(void); - -/** - * Restart writing to display after SPI deselecting it. - */ -void tftWriteRestart(void); - -/** - * Writes the given byte to display RAM. - * - * @param byte - */ -void tftWriteByte(uint8_t byte); - -/** - * Completes writing data to display RAM. - */ -void tftWriteEnd(void); - -/** - * Sets the given color in the given area of the display. - * - * @param x in pixels, origin top left - * @param y in pixels, origin top left - * @param width width in pixels - * @param height height in pixels - * @param color 16-Bit (5/6/5) RGB color - */ -void tftFillArea(x_t x, y_t y, - width_t width, height_t height, - uint16_t color); - -/** - * Sets the area to write image data to. - * - * @param x in pixels, origin top left - * @param y in pixels, origin top left - * @param width width in pixels - * @param height height in pixels - * @param hflip if image should be flipped horizontally - * @param vflip if image should be flipped vertically - */ -void tftSetArea(x_t x, y_t y, - width_t width, height_t height, - bool hflip, bool vflip); - -/** - * Sets the whole display to the given 16-Bit (5/6/5) RGB color. - * - * @param color - */ -void tftSetFrame(uint16_t color); - -/** - * Writes image data to the previously set area. - * - * @param bitmap pointer to bitmap data in program memory - * @param width width of the bitmap in pixels - * @param height height of the bitmap in pixels - * @param space color space of the bitmap - * @param bg background color (used only with SPACE_MONO1) - * @param fg foreground color (used only with SPACE_MONO1) - */ -void tftWriteData(const __flash uint8_t *bitmap, - width_t width, height_t height, - space_t space, uint16_t bg, uint16_t fg); - -/** - * Writes the bitmap with the given index to the given row and column - * and returns the width of the bitmap. - * - * @param x - * @param y - * @param index - * @param bg background color (used only with SPACE_MONO1) - * @param fg foreground color (used only with SPACE_MONO1) - * @return bitmap width - */ -width_t tftWriteBitmap(x_t x, y_t y, uint16_t index, - uint16_t bg, uint16_t fg); - -/** - * Writes the glyph with the given pseudo UTF-8 code point with the given - * font to the given row and column and returns the width of the glyph. - * - * @param x - * @param y - * @param font - * @param code - * @param bg background color (used only with SPACE_MONO1) - * @param fg foreground color (used only with SPACE_MONO1) - * @return glyph width - */ -width_t tftWriteGlyph(x_t x, y_t y, const __flash Font *font, code_t code, - uint16_t bg, uint16_t fg); - -/** - * Writes the given string with the given font to the given row and column - * and returns the width of the string. - * - * @param x - * @param y - * @param font - * @param string - * @param bg background color (used only with SPACE_MONO1) - * @param fg foreground color (used only with SPACE_MONO1) - * @return glyph width - */ -width_t tftWriteString(x_t x, y_t y, const __flash Font *font, const char *string, - uint16_t bg, uint16_t fg); - -#endif /* LIBTFT_H */ diff --git a/nbproject/Makefile-Custom.mk b/nbproject/Makefile-Custom.mk index 41e749a..74fe233 100644 --- a/nbproject/Makefile-Custom.mk +++ b/nbproject/Makefile-Custom.mk @@ -36,15 +36,14 @@ OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} # Object Files OBJECTFILES= \ ${OBJECTDIR}/_ext/48b9ad18/avrrfm.o \ + ${OBJECTDIR}/_ext/48b9ad18/bitmaps.o \ ${OBJECTDIR}/_ext/48b9ad18/i2c.o \ - ${OBJECTDIR}/_ext/48b9ad18/librfm69.o \ ${OBJECTDIR}/_ext/48b9ad18/mcp9808.o \ ${OBJECTDIR}/_ext/48b9ad18/rfm.o \ ${OBJECTDIR}/_ext/48b9ad18/sdc.o \ ${OBJECTDIR}/_ext/48b9ad18/spi.o \ - ${OBJECTDIR}/_ext/48b9ad18/usart.o \ - ${OBJECTDIR}/bitmaps.o \ - ${OBJECTDIR}/tft.o + ${OBJECTDIR}/_ext/48b9ad18/tft.o \ + ${OBJECTDIR}/_ext/48b9ad18/usart.o # C Compiler Flags @@ -73,43 +72,39 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/avrrfm: ${OBJECTFILES} ${OBJECTDIR}/_ext/48b9ad18/avrrfm.o: /home/dode/dev/avrrfm/avrrfm.c ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -std=c99 -o ${OBJECTDIR}/_ext/48b9ad18/avrrfm.o /home/dode/dev/avrrfm/avrrfm.c + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -std=c99 -o ${OBJECTDIR}/_ext/48b9ad18/avrrfm.o /home/dode/dev/avrrfm/avrrfm.c -${OBJECTDIR}/_ext/48b9ad18/i2c.o: /home/dode/dev/avrrfm/i2c.c +${OBJECTDIR}/_ext/48b9ad18/bitmaps.o: /home/dode/dev/avrrfm/bitmaps.c ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/_ext/48b9ad18/i2c.o /home/dode/dev/avrrfm/i2c.c + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -o ${OBJECTDIR}/_ext/48b9ad18/bitmaps.o /home/dode/dev/avrrfm/bitmaps.c -${OBJECTDIR}/_ext/48b9ad18/librfm69.o: /home/dode/dev/avrrfm/librfm69.c +${OBJECTDIR}/_ext/48b9ad18/i2c.o: /home/dode/dev/avrrfm/i2c.c ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/_ext/48b9ad18/librfm69.o /home/dode/dev/avrrfm/librfm69.c + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -o ${OBJECTDIR}/_ext/48b9ad18/i2c.o /home/dode/dev/avrrfm/i2c.c ${OBJECTDIR}/_ext/48b9ad18/mcp9808.o: /home/dode/dev/avrrfm/mcp9808.c ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/_ext/48b9ad18/mcp9808.o /home/dode/dev/avrrfm/mcp9808.c + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -o ${OBJECTDIR}/_ext/48b9ad18/mcp9808.o /home/dode/dev/avrrfm/mcp9808.c ${OBJECTDIR}/_ext/48b9ad18/rfm.o: /home/dode/dev/avrrfm/rfm.c ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/_ext/48b9ad18/rfm.o /home/dode/dev/avrrfm/rfm.c + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -o ${OBJECTDIR}/_ext/48b9ad18/rfm.o /home/dode/dev/avrrfm/rfm.c ${OBJECTDIR}/_ext/48b9ad18/sdc.o: /home/dode/dev/avrrfm/sdc.c ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/_ext/48b9ad18/sdc.o /home/dode/dev/avrrfm/sdc.c + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -o ${OBJECTDIR}/_ext/48b9ad18/sdc.o /home/dode/dev/avrrfm/sdc.c ${OBJECTDIR}/_ext/48b9ad18/spi.o: /home/dode/dev/avrrfm/spi.c ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -std=c99 -o ${OBJECTDIR}/_ext/48b9ad18/spi.o /home/dode/dev/avrrfm/spi.c + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -std=c99 -o ${OBJECTDIR}/_ext/48b9ad18/spi.o /home/dode/dev/avrrfm/spi.c -${OBJECTDIR}/_ext/48b9ad18/usart.o: /home/dode/dev/avrrfm/usart.c +${OBJECTDIR}/_ext/48b9ad18/tft.o: /home/dode/dev/avrrfm/tft.c ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/_ext/48b9ad18/usart.o /home/dode/dev/avrrfm/usart.c + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -o ${OBJECTDIR}/_ext/48b9ad18/tft.o /home/dode/dev/avrrfm/tft.c -${OBJECTDIR}/bitmaps.o: bitmaps.c - ${MKDIR} -p ${OBJECTDIR} - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/bitmaps.o bitmaps.c - -${OBJECTDIR}/tft.o: tft.c - ${MKDIR} -p ${OBJECTDIR} - $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/tft.o tft.c +${OBJECTDIR}/_ext/48b9ad18/usart.o: /home/dode/dev/avrrfm/usart.c + ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18 + $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=8000000UL -DRFM=95 -D__AVR_ATmega328P__ -D__flash=volatile -I. -I/home/dode/dev -o ${OBJECTDIR}/_ext/48b9ad18/usart.o /home/dode/dev/avrrfm/usart.c # Subprojects .build-subprojects: diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 73de51b..172aad5 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -5,7 +5,6 @@ avrrfm.c bitmaps.c i2c.c - librfm69.c mcp9808.c mcp9808.h rfm.c @@ -38,6 +37,7 @@ . + /home/dode/dev BAUD=38400 @@ -51,9 +51,9 @@ - + - + @@ -65,11 +65,9 @@ - + - - - + diff --git a/rfm.c b/rfm.c index e5da00d..df3f26e 100644 --- a/rfm.c +++ b/rfm.c @@ -7,7 +7,12 @@ #include -#include "librfm95.h" +#if RFM == 69 + #include "librfm69/librfm69.h" +#endif +#if RFM == 95 + #include "librfm95/librfm95.h" +#endif #include "pins.h" #include "spi.h" diff --git a/sdc.c b/sdc.c index 9bdcd9d..3c11582 100644 --- a/sdc.c +++ b/sdc.c @@ -7,7 +7,7 @@ #include -#include "libsdc.h" +#include "libsdc/libsdc.h" #include "pins.h" #include "spi.h" diff --git a/tft.c b/tft.c index 165d7f1..53964e3 100644 --- a/tft.c +++ b/tft.c @@ -7,7 +7,7 @@ #include -#include "libtft.h" +#include "libtft/libtft.h" #include "pins.h" #include "spi.h" diff --git a/types.h b/types.h index dfb7952..a5f3bfb 100644 --- a/types.h +++ b/types.h @@ -10,32 +10,7 @@ #include #include - -/* Width, height and color space of bitmaps and glyphs */ -typedef uint16_t width_t; -typedef uint16_t height_t; -typedef uint8_t space_t; - -/* Width * height * bytes per pixel */ -typedef uint32_t bytes_t; - -/* X and Y coordinates of the display */ -typedef uint16_t x_t; -typedef uint16_t y_t; - -/* Char code (like UTF-8 code point) */ -typedef uint8_t code_t; - -/* Number of glyphs of a font */ -typedef uint8_t length_t; - -/** - * A point with its x and y coordinates. - */ -typedef struct { - int16_t x; - int16_t y; -} Point; +#include "libtft/types.h" /** * Temperature read from transmitter including diff --git a/unifont.h b/unifont.h deleted file mode 100644 index 0850793..0000000 --- a/unifont.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * File: unifont.h - * Author: torsten.roemer@luniks.net - * Unifont is part of the GNU Project: http://savannah.gnu.org/projects/unifont/ - * - * Created on 8. April 2023, 16:50 - */ - -#ifndef UNIFONT_H -#define UNIFONT_H - -#include "font.h" - -/** - * Unifont font. - */ -extern const __flash Font unifontFont; - -#endif /* UNIFONT_H */ -