Skip to content

Commit

Permalink
fix(build): set SPI_DEV_DIR and SPI_SPEED macros
Browse files Browse the repository at this point in the history
Also improved logging.
  • Loading branch information
marvinmarnold committed Oct 20, 2021
1 parent ad32b84 commit 9c4b1d0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
# $OUTPUT_DIR/$SPI_BUS respectively. Also copies reset_lgw.sh
# to $OUTPUT_DIR.

FROM balenalib/raspberry-pi-debian:buster-build as sx1301-builder
FROM balenalib/raspberry-pi-debian:buster-build as lora-gateway-sx1301-builder

ENV ROOT_DIR=/opt

# Output built files to this location
ENV OUTPUT_DIR="$ROOT_DIR/output"

# Overwirtes value in loragw_spi.native.c
# https://github.com/NebraLtd/lora_gateway/blob/971c52e3e0f953102c0b057c9fff9b1df8a84d66/libloragw/src/loragw_spi.native.c#L56
# Used in libloragw/Makefile value and supplied to loragw_spi.native.c
ENV SPI_SPEED=2000000

WORKDIR "$ROOT_DIR"

# Copy upstream source into expected location
COPY . "$ROOT_DIR"

# Compile libloragw
RUN . "$ROOT_DIR/compile_libloragw.sh"
4 changes: 2 additions & 2 deletions compile_libloragw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ compile_libloragw_for_spi_bus() {
cd "$ROOT_DIR"
cp -r "$ROOT_DIR/libloragw/" "$OUTPUT_DIR/$spi_bus"

echo "Finished building libloragw for sx1301 on $spi_bus in $ROOT_DIR"
echo "Finished building libloragw for sx1301 on $spi_bus in $OUTPUT_DIR"
}

compile_libloragw() {
echo "Compiling libloragw for sx1301 concentrator on all the necessary SPI buses in $ROOT_DIR"
echo "Compiling libloragw for sx1301 concentrator on all the necessary SPI buses in $OUTPUT_DIR"

# Built outputs will be copied to this directory
mkdir -p "$OUTPUT_DIR"
Expand Down
3 changes: 2 additions & 1 deletion libloragw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ CROSS_COMPILE ?=
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar

CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I.
# Modified to include SPI_DEV_PATH and SPI_SPEED macros
CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I. -D'SPI_DEV_PATH="${SPI_DEV_DIR}"' -D'SPI_SPEED=${SPI_SPEED}'

OBJDIR = obj
INCLUDES = $(wildcard inc/*.h)
Expand Down
5 changes: 3 additions & 2 deletions libloragw/src/loragw_spi.native.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ Maintainer: Sylvain Miermont

#define READ_ACCESS 0x00
#define WRITE_ACCESS 0x80
#define SPI_SPEED 8000000
#define SPI_DEV_PATH "/dev/spidev0.0"
// SPI_SPEED and SPI_DEV_PATH are intended to be defined as part of CFLAGS in the Makefile
// #define SPI_SPEED 8000000
// #define SPI_DEV_PATH "/dev/spidev0.0"
//#define SPI_DEV_PATH "/dev/spidev32766.0"

/* -------------------------------------------------------------------------- */
Expand Down

0 comments on commit 9c4b1d0

Please sign in to comment.