diff --git a/Makefile b/Makefile index bcbad68..3e66925 100644 --- a/Makefile +++ b/Makefile @@ -2,15 +2,11 @@ # # Simplified version from: https://github.com/hexagon5un/AVR-Programming -MCU = atmega328p -F_CPU = 8000000 - MAIN = librfm.c CC = avr-gcc AR = avr-ar -CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL CFLAGS += -O2 -I. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CFLAGS += -Wall -Wstrict-prototypes @@ -29,7 +25,7 @@ OBJ = $(SRC:.c=.o) OBJ = $(SRC:.S=.o) -$(TARGET).o: librfm.h pins.h spi.h types.h utils.h Makefile +$(TARGET).o: librfm.h utils.h Makefile all: $(TARGET).a diff --git a/README.md b/README.md index 4fb96bf..5ceb95c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,16 @@ I'm impressed how well these radio modules work; the range achieved with simple wire antennas as well as the reliable packet transmission. +## TODO + +- Add support for RFM9x (LoRa) + +## Usage + +1. Include `librfm.h` and `librfm.a` in the project +2. To make the library device and CPU frequency independent, the +`_rfm*` functions in `librfm.h` must be implemented in the application + ## Range Setting `RegPaLevel` to `0x5f`, which gives +13 dBm with `PA1`, indoor range is diff --git a/librfm.c b/librfm.c index 773a80b..2e6436f 100644 --- a/librfm.c +++ b/librfm.c @@ -1,12 +1,12 @@ /* - * File: rfm69.c + * File: librfm.c * Author: torsten.roemer@luniks.net * * Created on 28. Januar 2025, 19:57 */ #include "librfm.h" -#include "types.h" +#include "utils.h" static volatile uint8_t irqFlags1 = 0; static volatile uint8_t irqFlags2 = 0; @@ -14,30 +14,16 @@ static volatile bool timeoutEnabled = false; /** - * Selects the radio to talk to via SPI. - */ -static void spiSel(void) { - PORT_RFM &= ~(1 << PIN_RCS); -} - -/** - * Deselects the radio to talk to via SPI. - */ -static void spiDes(void) { - PORT_RFM |= (1 << PIN_RCS); -} - -/** * Writes the given value to the given register. * * @param reg * @param value */ static void regWrite(uint8_t reg, uint8_t value) { - spiSel(); - transmit(reg | 0x80); - transmit(value); - spiDes(); + _rfmSel(); + _rfmTx(reg | 0x80); + _rfmTx(value); + _rfmDes(); } /** @@ -47,10 +33,10 @@ * @return value */ static uint8_t regRead(uint8_t reg) { - spiSel(); - transmit(reg & 0x7f); - uint8_t value = transmit(0x00); - spiDes(); + _rfmSel(); + _rfmTx(reg & 0x7f); + uint8_t value = _rfmTx(0x00); + _rfmDes(); return value; } @@ -87,14 +73,15 @@ irqFlags1 |= (1 << 2); } -void initRadio(uint64_t freq, uint8_t node) { +void rfmInit(uint64_t freq, uint8_t node) { // wait a bit after power on - _delay_ms(10); + _rfmDelay5(); + _rfmDelay5(); // pull reset LOW to turn on the module - PORT_RFM &= ~(1 << PIN_RRST); + _rfmOn(); - _delay_ms(5); + _rfmDelay5(); // uint8_t version = regRead(0x10); // printString("Version: "); @@ -199,55 +186,56 @@ /** * Reads interrupt flags when a radio interrupt occurs. */ -void intRadio(void) { +void rfmInt(void) { irqFlags1 = regRead(IRQ_FLAGS1); irqFlags2 = regRead(IRQ_FLAGS2); } -void timeRadio(void) { +void rfmTimer(void) { if (timeoutEnabled && timeoutInts++ >= TIMEOUT_INTS) { timeoutEnable(false); timeout(); } } -void sleepRadio(void) { +void rfmSleep(void) { setMode(MODE_SLEEP); } -void wakeRadio(void) { +void rfmWake(void) { setMode(MODE_STDBY); // should better wait for ModeReady irq? - _delay_ms(5); + _rfmDelay5(); } -void setNodeAddress(uint8_t address) { +void rfmSetNodeAddress(uint8_t address) { regWrite(NODE_ADDR, address); } -uint8_t getRssi(void) { +uint8_t rfmGetRssi(void) { return regRead(RSSI_VALUE); } -void setOutputPower(uint8_t rssi) { +// TODO make pure setter +void rfmSetOutputPower(uint8_t rssi) { uint8_t pa = 0x40; // -18 dBm with PA1 // adjust power from -2 to +13 dBm pa += min(max(rssi - 69, PA_MIN), PA_MAX); regWrite(PA_LEVEL, pa); } -uint8_t getOutputPower(void) { +uint8_t rfmGetOutputPower(void) { return regRead(PA_LEVEL); } -void startReceive(void) { +void rfmStartReceive(void) { // get "PayloadReady" on DIO0 regWrite(DIO_MAP1, 0x40); setMode(MODE_RX); } -PayloadFlags payloadReady(void) { +PayloadFlags rfmPayloadReady(void) { PayloadFlags flags = {.ready = false, .crc = false}; if (irqFlags2 & (1 << 2)) { flags.ready = true; @@ -259,33 +247,33 @@ return flags; } -size_t readPayload(uint8_t *payload, size_t size) { +size_t rfmReadPayload(uint8_t *payload, size_t size) { size_t len = regRead(FIFO); len = min(len, size); // TODO assume and ignore address for now regRead(FIFO); - spiSel(); - transmit(FIFO); + _rfmSel(); + _rfmTx(FIFO); for (size_t i = 0; i < len; i++) { - payload[i] = transmit(FIFO); + payload[i] = _rfmTx(FIFO); } - spiDes(); + _rfmDes(); return len; } -size_t receivePayload(uint8_t *payload, size_t size, bool timeout) { +size_t rfmReceivePayload(uint8_t *payload, size_t size, bool timeout) { timeoutEnable(timeout); - startReceive(); + rfmStartReceive(); // wait until "PayloadReady" or timeout do {} while (!(irqFlags2 & (1 << 2)) && !(irqFlags1 & (1 << 2))); bool ready = irqFlags2 & (1 << 2); bool timedout = irqFlags1 & (1 << 2); - clearIrqFlags(); + if (ready) { timeoutEnable(false); } @@ -298,28 +286,28 @@ return 0; } - return readPayload(payload, size); + return rfmReadPayload(payload, size); } -size_t transmitPayload(uint8_t *payload, size_t size, uint8_t node) { +size_t rfmTransmitPayload(uint8_t *payload, size_t size, uint8_t node) { // message + address byte size_t len = min(size, MESSAGE_SIZE) + 1; - spiSel(); - transmit(FIFO | 0x80); - transmit(len); - transmit(node); + _rfmSel(); + _rfmTx(FIFO | 0x80); + _rfmTx(len); + _rfmTx(node); for (size_t i = 0; i < size; i++) { - transmit(payload[i]); + _rfmTx(payload[i]); } - spiDes(); + _rfmDes(); // get "PacketSent" on DIO0 (default) regWrite(DIO_MAP1, 0x00); setMode(MODE_TX); - loop_until_bit_is_set(irqFlags2, 3); + do {} while (!(irqFlags2 & (1 << 3))); clearIrqFlags(); setMode(MODE_STDBY); diff --git a/librfm.h b/librfm.h index dda6da7..332d475 100644 --- a/librfm.h +++ b/librfm.h @@ -8,13 +8,9 @@ #ifndef LIBRFM_H #define LIBRFM_H +#include +#include #include -#include - -#include "pins.h" -#include "types.h" -#include "spi.h" -#include "utils.h" #define FIFO 0x00 #define OP_MODE 0x01 @@ -84,15 +80,57 @@ #define MAX_TIMEOUTS 9 // slow down tx attempts after so many timeouts /** + * Flags for "payload ready" event. + */ +typedef struct { + bool ready; + bool crc; +} PayloadFlags; + +/** + * F_CPU dependent delay of 5 milliseconds. + * _delay_ms(5); + * + * @param ms + */ +void _rfmDelay5(void); + +/** + * Turns the radio on by pulling its reset pin LOW. + * PORT_RFM &= ~(1 << PIN_RRST); + */ +void _rfmOn(void); + +/** + * Selects the radio to talk to via SPI. + * PORT_RFM &= ~(1 << PIN_RCS); + */ +void _rfmSel(void); + +/** + * Deselects the radio to talk to via SPI. + * PORT_RFM |= (1 << PIN_RCS); + */ +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 address. */ -void initRadio(uint64_t freq, uint8_t node); +void rfmInit(uint64_t freq, uint8_t node); /** * Should be called when a radio interrupt occurred, i.e. 'PayloadReady'. */ -void intRadio(void); +void rfmInt(void); /** * Gives a timer pulse to the radio. Used to time-out blocking functions, @@ -100,50 +138,50 @@ * TIMEOUT_INTS must be adjusted according to the frequency with that * this function is called. */ -void timeRadio(void); +void rfmTimer(void); /** * Shuts down the radio. */ -void sleepRadio(void); +void rfmSleep(void); /** * Wakes up the radio. */ -void wakeRadio(void); +void rfmWake(void); /** * Sets the node address. * * @param address */ -void setNodeAddress(uint8_t address); +void rfmSetNodeAddress(uint8_t address); /** * Returns the current RSSI value. * * @return rssi value */ -uint8_t getRssi(void); +uint8_t rfmGetRssi(void); /** * Sets the output power based on the given receiver RSSI. * * @param rssi */ -void setOutputPower(uint8_t rssi); +void rfmSetOutputPower(uint8_t rssi); /** * Returns the current output power setting. * * @return ouput power */ -uint8_t getOutputPower(void); +uint8_t rfmGetOutputPower(void); /** * Sets the radio to receive mode and maps "PayloadReady" to DIO0. */ -void startReceive(void); +void rfmStartReceive(void); /** * Returns true if a "PayloadReady" interrupt arrived and clears the @@ -151,7 +189,7 @@ * * @return true if "PayloadReady" */ -PayloadFlags payloadReady(void); +PayloadFlags rfmPayloadReady(void); /** * Sets the radio in standby mode, puts the payload into the given array @@ -161,7 +199,7 @@ * @param size of payload buffer * @return payload bytes actually received */ -size_t readPayload(uint8_t *payload, size_t size); +size_t rfmReadPayload(uint8_t *payload, size_t size); /** * Waits for "PayloadReady", puts the payload into the given array with the @@ -173,7 +211,7 @@ * @param timeout enable timeout * @return payload bytes actually received */ -size_t receivePayload(uint8_t *payload, size_t size, bool timeout); +size_t rfmReceivePayload(uint8_t *payload, size_t size, bool timeout); /** * Transmits up to 64 bytes of the given payload with the given node address. @@ -183,7 +221,7 @@ * @param node address * @return payload bytes actually sent */ -size_t transmitPayload(uint8_t *payload, size_t size, uint8_t node); +size_t rfmTransmitPayload(uint8_t *payload, size_t size, uint8_t node); #endif /* LIBRFM_H */ diff --git a/nbproject/Makefile-Custom.mk b/nbproject/Makefile-Custom.mk new file mode 100644 index 0000000..50bf3ef --- /dev/null +++ b/nbproject/Makefile-Custom.mk @@ -0,0 +1,79 @@ +# +# Generated Makefile - do not edit! +# +# Edit the Makefile in the project folder instead (../Makefile). Each target +# has a -pre and a -post target defined where you can add customized code. +# +# This makefile implements configuration specific macros and targets. + + +# Environment +MKDIR=mkdir +CP=cp +GREP=grep +NM=nm +CCADMIN=CCadmin +RANLIB=ranlib +CC=avr-gcc +CCC=avr-g++ +CXX=avr-g++ +FC=gfortran +AS=avr-as + +# Macros +CND_PLATFORM=AVR-Linux +CND_DLIB_EXT=so +CND_CONF=Custom +CND_DISTDIR=dist +CND_BUILDDIR=build + +# Include project Makefile +include /home/dode/dev/librfm/Makefile + +# Object Directory +OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} + +# Object Files +OBJECTFILES= \ + ${OBJECTDIR}/_ext/5ac08470/librfm.o + + +# C Compiler Flags +CFLAGS= + +# CC Compiler Flags +CCFLAGS= +CXXFLAGS= + +# Fortran Compiler Flags +FFLAGS= + +# Assembler Flags +ASFLAGS= + +# Link Libraries and Options +LDLIBSOPTIONS= + +# Build Targets +.build-conf: ${BUILD_SUBPROJECTS} + "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/liblibrfm.a + +${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/liblibrfm.a: ${OBJECTFILES} + ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} + ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/liblibrfm.a + ${AR} -rv ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/liblibrfm.a ${OBJECTFILES} + $(RANLIB) ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/liblibrfm.a + +${OBJECTDIR}/_ext/5ac08470/librfm.o: /home/dode/dev/librfm/librfm.c + ${MKDIR} -p ${OBJECTDIR}/_ext/5ac08470 + $(COMPILE.c) -g -o ${OBJECTDIR}/_ext/5ac08470/librfm.o /home/dode/dev/librfm/librfm.c + +# Subprojects +.build-subprojects: + +# Clean Targets +.clean-conf: ${CLEAN_SUBPROJECTS} + ${RM} -r ${CND_BUILDDIR}/${CND_CONF} + +# Subprojects +.clean-subprojects: diff --git a/nbproject/Makefile-impl.mk b/nbproject/Makefile-impl.mk new file mode 100644 index 0000000..99db176 --- /dev/null +++ b/nbproject/Makefile-impl.mk @@ -0,0 +1,133 @@ +# +# Generated Makefile - do not edit! +# +# Edit the Makefile in the project folder instead (../Makefile). Each target +# has a pre- and a post- target defined where you can add customization code. +# +# This makefile implements macros and targets common to all configurations. +# +# NOCDDL + + +# Building and Cleaning subprojects are done by default, but can be controlled with the SUB +# macro. If SUB=no, subprojects will not be built or cleaned. The following macro +# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf +# and .clean-reqprojects-conf unless SUB has the value 'no' +SUB_no=NO +SUBPROJECTS=${SUB_${SUB}} +BUILD_SUBPROJECTS_=.build-subprojects +BUILD_SUBPROJECTS_NO= +BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}} +CLEAN_SUBPROJECTS_=.clean-subprojects +CLEAN_SUBPROJECTS_NO= +CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} + + +# Project Name +PROJECTNAME=librfm + +# Active Configuration +DEFAULTCONF=Custom +CONF=${DEFAULTCONF} + +# All Configurations +ALLCONFS=Custom + + +# build +.build-impl: .build-pre .validate-impl .depcheck-impl + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf + + +# clean +.clean-impl: .clean-pre .validate-impl .depcheck-impl + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf + + +# clobber +.clobber-impl: .clobber-pre .depcheck-impl + @#echo "=> Running $@..." + for CONF in ${ALLCONFS}; \ + do \ + "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ + done + +# all +.all-impl: .all-pre .depcheck-impl + @#echo "=> Running $@..." + for CONF in ${ALLCONFS}; \ + do \ + "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf; \ + done + +# build tests +.build-tests-impl: .build-impl .build-tests-pre + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-tests-conf + +# run tests +.test-impl: .build-tests-impl .test-pre + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .test-conf + +# dependency checking support +.depcheck-impl: + @echo "# This code depends on make tool being used" >.dep.inc + @if [ -n "${MAKE_VERSION}" ]; then \ + echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES} \$${TESTOBJECTFILES}))" >>.dep.inc; \ + echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ + echo "include \$${DEPFILES}" >>.dep.inc; \ + echo "endif" >>.dep.inc; \ + else \ + echo ".KEEP_STATE:" >>.dep.inc; \ + echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ + fi + +# configuration validation +.validate-impl: + @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ + then \ + echo ""; \ + echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ + echo "See 'make help' for details."; \ + echo "Current directory: " `pwd`; \ + echo ""; \ + fi + @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ + then \ + exit 1; \ + fi + + +# help +.help-impl: .help-pre + @echo "This makefile supports the following configurations:" + @echo " ${ALLCONFS}" + @echo "" + @echo "and the following targets:" + @echo " build (default target)" + @echo " clean" + @echo " clobber" + @echo " all" + @echo " help" + @echo "" + @echo "Makefile Usage:" + @echo " make [CONF=] [SUB=no] build" + @echo " make [CONF=] [SUB=no] clean" + @echo " make [SUB=no] clobber" + @echo " make [SUB=no] all" + @echo " make help" + @echo "" + @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," + @echo " also build subprojects." + @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," + @echo " also clean subprojects." + @echo "Target 'clobber' will remove all built files from all configurations and," + @echo " unless 'SUB=no', also from subprojects." + @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," + @echo " also build subprojects." + @echo "Target 'help' prints this message." + @echo "" + diff --git a/nbproject/Makefile-variables.mk b/nbproject/Makefile-variables.mk new file mode 100644 index 0000000..2c19f0b --- /dev/null +++ b/nbproject/Makefile-variables.mk @@ -0,0 +1,27 @@ +# +# Generated - do not edit! +# +# NOCDDL +# +CND_BASEDIR=`pwd` +CND_BUILDDIR=build +CND_DISTDIR=dist +# Custom configuration +CND_PLATFORM_Custom=AVR-Linux +CND_ARTIFACT_DIR_Custom=dist/Custom/AVR-Linux +CND_ARTIFACT_NAME_Custom=liblibrfm.a +CND_ARTIFACT_PATH_Custom=dist/Custom/AVR-Linux/liblibrfm.a +CND_PACKAGE_DIR_Custom=dist/Custom/AVR-Linux/package +CND_PACKAGE_NAME_Custom=librfm.tar +CND_PACKAGE_PATH_Custom=dist/Custom/AVR-Linux/package/librfm.tar +# +# include compiler specific variables +# +# dmake command +ROOT:sh = test -f nbproject/private/Makefile-variables.mk || \ + (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk) +# +# gmake command +.PHONY: $(shell test -f nbproject/private/Makefile-variables.mk || (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk)) +# +include nbproject/private/Makefile-variables.mk diff --git a/nbproject/Package-Custom.bash b/nbproject/Package-Custom.bash new file mode 100644 index 0000000..63e73d6 --- /dev/null +++ b/nbproject/Package-Custom.bash @@ -0,0 +1,76 @@ +#!/bin/bash -x + +# +# Generated - do not edit! +# + +# Macros +TOP=`pwd` +CND_PLATFORM=AVR-Linux +CND_CONF=Custom +CND_DISTDIR=dist +CND_BUILDDIR=build +CND_DLIB_EXT=so +NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging +TMPDIRNAME=tmp-packaging +OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/liblibrfm.a +OUTPUT_BASENAME=liblibrfm.a +PACKAGE_TOP_DIR=librfm/ + +# Functions +function checkReturnCode +{ + rc=$? + if [ $rc != 0 ] + then + exit $rc + fi +} +function makeDirectory +# $1 directory path +# $2 permission (optional) +{ + mkdir -p "$1" + checkReturnCode + if [ "$2" != "" ] + then + chmod $2 "$1" + checkReturnCode + fi +} +function copyFileToTmpDir +# $1 from-file path +# $2 to-file path +# $3 permission +{ + cp "$1" "$2" + checkReturnCode + if [ "$3" != "" ] + then + chmod $3 "$2" + checkReturnCode + fi +} + +# Setup +cd "${TOP}" +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package +rm -rf ${NBTMPDIR} +mkdir -p ${NBTMPDIR} + +# Copy files and create directories and links +cd "${TOP}" +makeDirectory "${NBTMPDIR}/librfm/lib" +copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644 + + +# Generate tar file +cd "${TOP}" +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/librfm.tar +cd ${NBTMPDIR} +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/librfm.tar * +checkReturnCode + +# Cleanup +cd "${TOP}" +rm -rf ${NBTMPDIR} diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 61fa6c1..150f8b5 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -18,26 +18,16 @@ /home/dode/dev/librfm/Makefile - + AVR|GNU false false - - - - - /home/dode/dev/librfm - ${MAKE} -f Makefile - ${MAKE} -f Makefile clean - - - - . - - - + + + + diff --git a/nbproject/project.xml b/nbproject/project.xml index 94e0375..bb4b63c 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -14,8 +14,8 @@ - Default - 0 + Custom + 3 diff --git a/pins.h b/pins.h deleted file mode 100644 index c8cf6ce..0000000 --- a/pins.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * File: pins.h - * Author: torsten.roemer@luniks.net - * - * Created on 1. April 2023, 19:25 - */ - -#ifndef PINS_H -#define PINS_H - -#include - -/* SPI */ -#define DDR_SPI DDRB -#define PORT_SPI PORTB -#define PIN_SS PB2 -#define PIN_MOSI PB3 -#define PIN_MISO PB4 -#define PIN_SCK PB5 - -/* I2C */ -#define DDR_I2C DDRC -#define PORT_I2C PORTC -#define PIN_SCL PC5 -#define PIN_SDA PC4 - -/* Radio Int */ -#define PIN_RINT PD2 // radio interrupt - -/* Radio SPI */ -#define DDR_RFM DDRB -#define PORT_RFM PORTB -#define PIN_RCS PB1 // radio chip select -#define PIN_RRST PB0 // radio reset - -/* SD Card */ -#define DDR_SDC DDRD -#define PORT_SDC PORTD -#define PIN_SDCS PD4 // sdcard chip select - -/* Display */ -#define DDR_DISP DDRD -#define PORT_DISP PORTD -#define PIN_DCS PD5 // display chip select -#define PIN_DDC PD6 // display data/command -#define PIN_DRST PD7 // display reset - -#endif /* PINS_H */ diff --git a/spi.h b/spi.h deleted file mode 100644 index e9c3f66..0000000 --- a/spi.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * File: spi.h - * Author: torsten.roemer@luniks.net - * - * Created on 1. April 2023, 19:12 - */ - -#ifndef SPI_H -#define SPI_H - -#include -#include -#include "pins.h" - -/** - * Sets slow SPI speed. - */ -void spiSlow(void); - -/** - * Sets fast SPI speed. - */ -void spiFast(void); - -/** - * Transmits the given byte and returns the byte reveived at the same time. - * @param data byte to be written - * @return byte read while writing - */ -uint8_t transmit(uint8_t data); - -#endif /* SPI_H */ - diff --git a/types.h b/types.h deleted file mode 100644 index f15e271..0000000 --- a/types.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * File: types.h - * Author: torsten.roemer@luniks.net - * - * Created on 17. September 2023, 20:33 - */ - -#ifndef TYPES_H -#define TYPES_H - -#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; - -/** - * Flags for "payload ready" event. - */ -typedef struct { - bool ready; - bool crc; -} PayloadFlags; - -/** - * Temperature read from transmitter including - * additional information. - */ -typedef struct { - uint16_t raw; - uint8_t power; -} Temperature; - -/** - * Pointer to a function that takes no argument and returns void. - */ -typedef void (*Function)(void); - -/** - * Pointer to a function that takes an array of bytes - * and returns a boolean. - */ -typedef bool (*Consumer)(uint8_t*); - -#endif /* TYPES_H */ -