Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: ci

on:
pull_request:
push:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint
run: |
make fmt
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.ruff_cache/
tools/
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-added-large-files
#- id: mixed-line-ending
# args: [ --fix=lf ]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
hooks:
- id: ruff
args: [ --fix ]
- id: ruff
args: [ --fix, --select, I ] # import sorting
- id: ruff-format

exclude: 'lib/examples/*'
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.PHONY: all
all: .venv pre-commit-install help

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development

.venv: ## Create a virtual environment
@echo "Creating virtual environment..."
@$(MAKE) uv
@$(UV) venv
@$(UV) pip install --requirement pyproject.toml

.PHONY: pre-commit-install
pre-commit-install: uv
@echo "Installing pre-commit hooks..."
@$(UVX) pre-commit install > /dev/null

.PHONY: fmt
fmt: pre-commit-install ## Lint and format files
$(UVX) pre-commit run --all-files

typecheck: .venv ## Run type check
@$(UV) run -m pyright .

.PHONY: clean
clean: ## Remove all gitignored files
git clean -dfX

##@ Build Tools
TOOLS_DIR ?= tools
$(TOOLS_DIR):
mkdir -p $(TOOLS_DIR)

### Tool Versions
UV_VERSION ?= 0.5.24

UV_DIR ?= $(TOOLS_DIR)/uv-$(UV_VERSION)
UV ?= $(UV_DIR)/uv
UVX ?= $(UV_DIR)/uvx
.PHONY: uv
uv: $(UV) ## Download uv
$(UV): $(TOOLS_DIR)
@test -s $(UV) || { mkdir -p $(UV_DIR); curl -LsSf https://astral.sh/uv/$(UV_VERSION)/install.sh | UV_INSTALL_DIR=$(UV_DIR) sh > /dev/null; }
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ CircuitPython driver for the Semtech SX1280 LoRa chip (2.4 GHz)

## 🚧 Under construction. Use at your own risk!

### Status:
- [x] init and configure
### Status:
- [x] init and configure
- [x] confirm Tx - [see example_tx](example_tx.py)
- [x] confirm Rx
- [x] exchange packet(s)
- [x] confirm ranging
- [ ] make library user friendly

NOTE: only LoRa aspects implemented thus far. lots of things are hard-coded in. Nearly all LoRa functionality is available (Tx, Rx, Ranging), but message buffer handling isn't streamlined yet.

NOTE: only LoRa aspects implemented thus far. lots of things are hard-coded in. Nearly all LoRa functionality is available (Tx, Rx, Ranging), but message buffer handling isn't streamlined yet.
2 changes: 1 addition & 1 deletion example.py → examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

radio = sx1280.SX1280(spi, CS, RESET, BUSY)
radio = sx1280.SX1280(spi, CS, RESET, BUSY)
12 changes: 7 additions & 5 deletions example_ranging_master.py → examples/example_ranging_master.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import board,time
import time

import board
import busio
import digitalio

import sx1280

CS = digitalio.DigitalInOut(board.D35)
RESET = digitalio.DigitalInOut(board.D36)
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
DIO1 = digitalio.DigitalInOut(board.D41)
DIO2 = digitalio.DigitalInOut(board.D42)
DIO3 = digitalio.DigitalInOut(board.D38)
Expand All @@ -24,9 +26,9 @@
while True:
radio.range()
time.sleep(4)
status=radio.get_Irq_Status()
status = radio.get_Irq_Status()
if status[2] > 0 or status[3] > 0:
data1 = radio.read_range(raw=False)
print('Filtered:',data1)
print("Filtered:", data1)
data2 = radio.read_range(raw=True)
print('Raw:\t',data2)
print("Raw:\t", data2)
10 changes: 6 additions & 4 deletions example_ranging_slave.py → examples/example_ranging_slave.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import board,time
import time

import board
import busio
import digitalio

import sx1280

CS = digitalio.DigitalInOut(board.D35)
RESET = digitalio.DigitalInOut(board.D36)
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
DIO1 = digitalio.DigitalInOut(board.D41)
DIO2 = digitalio.DigitalInOut(board.D42)
DIO3 = digitalio.DigitalInOut(board.D38)
Expand All @@ -25,5 +27,5 @@
time.sleep(5)
status = radio.get_Irq_Status()
if status[2] > 0 or status[3] > 0:
[print(hex(i)+' ',end='') for i in status]
print('')
[print(hex(i) + " ", end="") for i in status]
print("")
14 changes: 8 additions & 6 deletions example_rx.py → examples/example_rx.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'''
"""
Working RX example for SX1280 breakout using SAM32
'''
"""

import board,time
import time

import board
import busio
import digitalio

import sx1280

CS = digitalio.DigitalInOut(board.D35)
RESET = digitalio.DigitalInOut(board.D36)
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
DIO1 = digitalio.DigitalInOut(board.D41)
DIO2 = digitalio.DigitalInOut(board.D42)
DIO3 = digitalio.DigitalInOut(board.D31)
Expand All @@ -28,6 +30,6 @@

while True:
msg = radio.receive()
if msg != None:
if msg is not None:
print(msg, radio.packet_status)
time.sleep(1)
time.sleep(1)
18 changes: 10 additions & 8 deletions example_tx.py → examples/example_tx.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'''
"""
Working TX example for SX1280 breakout using SAM32
'''
"""

import board,time
import time

import board
import busio
import digitalio

import sx1280

CS = digitalio.DigitalInOut(board.D35)
RESET = digitalio.DigitalInOut(board.D36)
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
DIO1 = digitalio.DigitalInOut(board.D41)
DIO2 = digitalio.DigitalInOut(board.D42)
DIO3 = digitalio.DigitalInOut(board.D31)
Expand All @@ -23,8 +25,8 @@

radio = sx1280.SX1280(spi, CS, RESET, BUSY, debug=False)

cnt=0
cnt = 0
while True:
cnt+=1
radio.send('ping'+str(cnt))
time.sleep(1)
cnt += 1
radio.send("ping" + str(cnt))
time.sleep(1)
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[project]
name = "proves-circuitpython-sx1280"
version = "2.0.0"
description = "Flight Software for the PROVES Kit"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"adafruit-circuitpython-typing==1.11.2",
"circuitpython-stubs==9.2.5",
"pyright[nodejs]==1.1.399",
"pre-commit==4.0.1",
]

[tool.setuptools]
packages = [
"sx1280",
]

[tool.ruff.format]
# Use `\n` line endings for all files
line-ending = "lf"

[tool.pyright]
include = ["sx1280.py"]
exclude = [
"**/__pycache__",
".venv",
".git",
"examples",
"typings",
]
stubPath = "./typings"
reportMissingModuleSource = false
Loading