optimized spi

This commit is contained in:
Brett Weiland 2025-05-11 00:35:14 -05:00
parent 349326cd1c
commit e835229907
1486 changed files with 1187124 additions and 6067 deletions

9
.gitignore vendored
View File

@ -1,9 +0,0 @@
# the CSVs of all my parts are ommitted, since I bought some parts that were wrong. I will draft up an official parts list later, or you can ask me now at brettsweiland@gmail.com.
programmer_fix/
stm32card_first.csv
**/.gdbhistory*/
v1_output/
kicad/stm32card/stm32card-backups/*
LCSC_Quote_Exported__20250213_081540.csv
3dprint_tests/
**/build/*

View File

@ -1,45 +1,10 @@
# STM32 Mandelbrot Explorer Buisness Card
A battery powered business card that can explore the Mandelbrot set. Meant to be cheaply made for handing out. Will likely include a flappy bird clone to encourage recruiter competition.
# Project in development! See below for a brief write up.
# STM32 Buisnesscard Manelbrot Explorer
## Waiting on PCBs for first prototype!
![STM32 Card Prototype 1](https://git.bpcspace.com/indigo/stm32_business_card/raw/branch/main/preview.png)
## Project structure
Code: [program/stm32f1_buisnesscard_v1/Core](https://git.bpcspace.com/indigo/stm32_business_card/src/branch/main/program/stm32f1_buisnesscard_v1/Core) <br>
PCB: [kicad/](https://git.bpcspace.com/indigo/stm32_business_card/src/branch/main/kicad)
## Software Development
The software is currently working, but is more a proof of concept (messy and unoptimized). In it's current state, I'm leaning heavily on ST's HAL to save time. For a project where everything is written from the ground up, see my other projects below [^1]!
### Display
I've modified [this repository](https://github.com/afiskon/stm32-st7735) to fit my needs. I've had to make some minor changes to utilize the ST7735's sleep mode, and to make the code work for my specific display. I expect I'll need to rewrite the library to manipulate raw registers to optimize SPI communication, as it currently uses HAL and is *very* slow. I'm considering implementing a game as well, which may require I access SPI via DMA.
### (No) FPU
The STM32F1 lineup doesn't have an FPU, thus fixed point integer arithmetic is used to speed up rendering. The decimal is intentionally too close to the MSB, as this introduces aesthetic visual artifacts at no cost that I think are a nice twist. <br>
*notice the banding around the set- that's an artifact of pushing fixed point arithmatic beyond its limits* <br>
<img src="./writeup/quick_buildings.png" alt="drawing" width="800"/> <br>
<img src="./writeup/quick_spiral.png" alt="drawing" width="800"/> <br>
### MCU Power Consumption
The software is interrupt based, saving power any time there's not an active job. After 30 seconds, a MOSFET will turn off the backlight and the MCU will in a deeper sleep state, where only a few microamps are consumed. This allows the card to operate without a power switch, as theoretically the sleeping power consumption is insignificant compared to the shelf life of these batteries (a few months).
## Hardware Development
The PCB works, and is what I'm using to test code. I'm planning on making some changes, including adding MOSFETS for the display backlight and creating some art for the silk screen.
The hardware is intentionally left simple for rapid development; there's two ideal diodes, allowing power delivery via USB-C or batteries, a step-down switching regulator, buttons with debouncing circuits, and of course, the MCU.
Some of the most vital components are described below.
### Batteries
This card will be powered by 4 zinc air batteries (cost effective & high power density, commonly used in hearing aids). The downside to these batteries is that they're non-rechargeable, and after activation, they only have a shelf life of a few weeks. Batteries are expensive, and what I've got is more then enough- it may actually be overkill.
A battery holder was developed to be used with springs to hold the batteries in place. I haven't ordered the batteries yet, so I have yet to see how it performs.
### Display
The display is the cheapest 2$ 65k 160x80 color LCD I could find on LCSC. It is the most expensive part of my card, matched with batteries. I'm sure I could have found it on Ali Express for 50¢, but hindsight is 20/20. It's actually very pretty, and I plan to upload images soon.
### SPI troubles
Currently, SPI only works consistently at 4mHZ. I have yet to probe it with my oscilloscope and figure out what's wrong; I'm guessing parasitic capacitance. My next PCB will have differential routing to allow higher speeds.
## Things I'd change
I'm used to working with a lot lower spec MCUs, and after the purchase I've found that the price of the STM32f1 is actually quite expensive for it's performance. I might want to try something uber cheap for my next project requiring a higher speed 32 bit processor, as long as it's got a HAL to accelerate development. The ch32v003 looks pretty cool...
## Other Projects
[^1]: For another embedded project without any assistance from HAL, check out my (unfinished) [AVR wristwatch](https://git.bpcspace.com/indigo/AVRwristwatch), where everything- from the I2C display and RTC clock is developed from the ground up! <br>
For a much larger project that's not exactly embedded, check out my [Operating System](https://git.bpcspace.com/indigo/IndigoOS). I haven't been able to work on it since going to Missouri S&T, but some impressive feats include a bootloader, an efficient binary tree/buddy system physical memory allocator, and multi-core execution. It's a lot of code, maybe check it out!
## This project is actively in progress!
## Description
This card will be powered by 4 zink air batteries (cost effective & high enough discharge) and will allow exploration of the mandelbrot fractal. Cost per card is projected to be about 7$, although I'm spending a lot more money learning.
A cheaper MCU could be used, but I decided to go with something that has a developed ecosystem to save time. If you'd like to see software built from the ground up, without any HAL, see my wristwatch project.
## Directories
The recon folder are just some experiments I ran to get familiar with STM32.
I've finished the schematic (see kicad folder), I'm now working on the PCB. It will likely be finished after the career fair.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

File diff suppressed because it is too large Load Diff

View File

@ -109,6 +109,7 @@
(psnegative no)
(psa4output no)
(plot_black_and_white yes)
(plotinvisibletext no)
(sketchpadsonfab no)
(plotpadnumbers no)
(hidednponfab no)
@ -7784,432 +7785,432 @@
)
)
)
(pad "1" smd rect
(at -2.75 4.1 90)
(size 0.27 1.2)
(pad "1" smd oval
(at -2.75 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 3 "Net-(U4-VBAT)")
(pinfunction "VBAT")
(pintype "unspecified")
(uuid "e79ab2a6-1796-442f-88fa-db289bfa48a0")
)
(pad "2" smd rect
(at -2.25 4.1 90)
(size 0.27 1.2)
(pad "2" smd oval
(at -2.25 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 26 "unconnected-(U4-PC13-TAMPER-RTC-Pad2)")
(pinfunction "PC13-TAMPER-RTC")
(pintype "unspecified")
(uuid "1a05e960-2a55-4f71-b147-e96e8a89e0fe")
)
(pad "3" smd rect
(at -1.75 4.1 90)
(size 0.27 1.2)
(pad "3" smd oval
(at -1.75 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 30 "unconnected-(U4-PC14-OSC32_IN-Pad3)")
(pinfunction "PC14-OSC32_IN")
(pintype "unspecified")
(uuid "73b6275e-19b3-4779-96c5-1a245d7144ce")
)
(pad "4" smd rect
(at -1.25 4.1 90)
(size 0.27 1.2)
(pad "4" smd oval
(at -1.25 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 28 "unconnected-(U4-PC15-OSC32_OUT-Pad4)")
(pinfunction "PC15-OSC32_OUT")
(pintype "unspecified")
(uuid "28b47442-9173-4d4f-a2fb-2b1653c691f1")
)
(pad "5" smd rect
(at -0.75 4.1 90)
(size 0.27 1.2)
(pad "5" smd oval
(at -0.75 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 43 "unconnected-(U4-PD0-OSC_IN-Pad5)")
(pinfunction "PD0-OSC_IN")
(pintype "unspecified")
(uuid "ab0b34da-d5ed-424f-a8ab-9a02141a4969")
)
(pad "6" smd rect
(at -0.25 4.1 90)
(size 0.27 1.2)
(pad "6" smd oval
(at -0.25 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 31 "unconnected-(U4-PD1-OSC_OUT-Pad6)")
(pinfunction "PD1-OSC_OUT")
(pintype "unspecified")
(uuid "77f01d04-c1c5-45e0-81bb-046fdd98ae5c")
)
(pad "7" smd rect
(at 0.25 4.1 90)
(size 0.27 1.2)
(pad "7" smd oval
(at 0.25 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 59 "Net-(U4-NRST)")
(pinfunction "NRST")
(pintype "unspecified")
(uuid "dcac7642-6b3d-43a7-997d-f00a139d4ab0")
)
(pad "8" smd rect
(at 0.75 4.1 90)
(size 0.27 1.2)
(pad "8" smd oval
(at 0.75 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 1 "GND")
(pinfunction "VSSA")
(pintype "unspecified")
(uuid "75228e14-830c-407e-9e11-f0ea5a14b10d")
)
(pad "9" smd rect
(at 1.25 4.1 90)
(size 0.27 1.2)
(pad "9" smd oval
(at 1.25 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 2 "+3V0")
(pinfunction "VDDA")
(pintype "unspecified")
(uuid "9d9f523d-8b64-49b3-a65e-4785152cb0b3")
)
(pad "10" smd rect
(at 1.75 4.1 90)
(size 0.27 1.2)
(pad "10" smd oval
(at 1.75 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 14 "in_button_down")
(pinfunction "PA0-WKUP")
(pintype "unspecified")
(uuid "9038ef2a-c022-477d-a7af-2aed110664bf")
)
(pad "11" smd rect
(at 2.25 4.1 90)
(size 0.27 1.2)
(pad "11" smd oval
(at 2.25 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 16 "in_button_right")
(pinfunction "PA1")
(pintype "unspecified")
(uuid "9bd2c635-b737-4f46-b335-6872129d0bb1")
)
(pad "12" smd rect
(at 2.75 4.1 90)
(size 0.27 1.2)
(pad "12" smd oval
(at 2.75 4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 15 "in_button_left")
(pinfunction "PA2")
(pintype "unspecified")
(uuid "810a7c66-5c51-4218-ab71-ba62e41fb87d")
)
(pad "13" smd rect
(at 4.1 2.75 90)
(size 1.2 0.27)
(pad "13" smd oval
(at 4.25 2.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 17 "in_button_up")
(pinfunction "PA3")
(pintype "unspecified")
(uuid "8a779d3e-67f8-48c5-987a-4f051bf7d321")
)
(pad "14" smd rect
(at 4.1 2.25 90)
(size 1.2 0.27)
(pad "14" smd oval
(at 4.25 2.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 34 "unconnected-(U4-PA4-Pad14)")
(pinfunction "PA4")
(pintype "unspecified")
(uuid "92a65f03-7ad3-42e5-af53-52602856aa1c")
)
(pad "15" smd rect
(at 4.1 1.75 90)
(size 1.2 0.27)
(pad "15" smd oval
(at 4.25 1.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 20 "spi1_sck")
(pinfunction "PA5")
(pintype "unspecified")
(uuid "32e2cd59-1a1a-4a60-84a0-d576940aad30")
)
(pad "16" smd rect
(at 4.1 1.25 90)
(size 1.2 0.27)
(pad "16" smd oval
(at 4.25 1.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 49 "spi1_miso")
(pinfunction "PA6")
(pintype "unspecified")
(uuid "fdbb6c52-95a6-4fde-82f2-47adf573ec4a")
)
(pad "17" smd rect
(at 4.1 0.75 90)
(size 1.2 0.27)
(pad "17" smd oval
(at 4.25 0.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 22 "spi1_mosi")
(pinfunction "PA7")
(pintype "unspecified")
(uuid "e792b8c6-90a2-4926-ba45-e0cba4cabc42")
)
(pad "18" smd rect
(at 4.1 0.25 90)
(size 1.2 0.27)
(pad "18" smd oval
(at 4.25 0.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 53 "lcd_dataselect")
(pinfunction "PB0")
(pintype "unspecified")
(uuid "9f744027-3ace-4393-99a0-b336b4d81503")
)
(pad "19" smd rect
(at 4.1 -0.25 90)
(size 1.2 0.27)
(pad "19" smd oval
(at 4.25 -0.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 33 "lcd_reset")
(pinfunction "PB1")
(pintype "unspecified")
(uuid "566d4e9c-be81-4101-898b-e5c6d19a406d")
)
(pad "20" smd rect
(at 4.1 -0.75 90)
(size 1.2 0.27)
(pad "20" smd oval
(at 4.25 -0.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 55 "lcd_cs")
(pinfunction "PB2")
(pintype "unspecified")
(uuid "e3c72a81-422c-4a4e-bfd8-52c744114e68")
)
(pad "21" smd rect
(at 4.1 -1.25 90)
(size 1.2 0.27)
(pad "21" smd oval
(at 4.25 -1.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 32 "unconnected-(U4-PB10-Pad21)")
(pinfunction "PB10")
(pintype "unspecified")
(uuid "7e9823b4-5e4f-4346-bd89-f93d913a0470")
)
(pad "22" smd rect
(at 4.1 -1.75 90)
(size 1.2 0.27)
(pad "22" smd oval
(at 4.25 -1.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 40 "unconnected-(U4-PB11-Pad22)")
(pinfunction "PB11")
(pintype "unspecified")
(uuid "939d3526-f560-48ea-afb8-980d166c0254")
)
(pad "23" smd rect
(at 4.1 -2.25 90)
(size 1.2 0.27)
(pad "23" smd oval
(at 4.25 -2.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 1 "GND")
(pinfunction "VSS_1")
(pintype "unspecified")
(uuid "7440ebae-93d6-4309-bb3a-bbcf01e45ad4")
)
(pad "24" smd rect
(at 4.1 -2.75 90)
(size 1.2 0.27)
(pad "24" smd oval
(at 4.25 -2.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 2 "+3V0")
(pinfunction "VDD_1")
(pintype "unspecified")
(uuid "d82a8937-2e8a-4bb7-9f80-a9b84b9e8f52")
)
(pad "25" smd rect
(at 2.75 -4.1 90)
(size 0.27 1.2)
(pad "25" smd oval
(at 2.75 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 25 "power_info")
(pinfunction "PB12")
(pintype "unspecified")
(uuid "1294e193-e0ff-4292-b140-594a112ae602")
)
(pad "26" smd rect
(at 2.25 -4.1 90)
(size 0.27 1.2)
(pad "26" smd oval
(at 2.25 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 11 "in_button_a")
(pinfunction "PB13")
(pintype "unspecified")
(uuid "218f6e51-f6a2-4547-9719-ff66b2109f2f")
)
(pad "27" smd rect
(at 1.75 -4.1 90)
(size 0.27 1.2)
(pad "27" smd oval
(at 1.75 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 13 "in_button_b")
(pinfunction "PB14")
(pintype "unspecified")
(uuid "b43c9964-3dd0-40e5-a924-4e4afa1a0acf")
)
(pad "28" smd rect
(at 1.25 -4.1 90)
(size 0.27 1.2)
(pad "28" smd oval
(at 1.25 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 42 "unconnected-(U4-PB15-Pad28)")
(pinfunction "PB15")
(pintype "unspecified")
(uuid "a069a5f1-68ad-46ff-86b9-7595c6f139b6")
)
(pad "29" smd rect
(at 0.75 -4.1 90)
(size 0.27 1.2)
(pad "29" smd oval
(at 0.75 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 36 "unconnected-(U4-PA8-Pad29)")
(pinfunction "PA8")
(pintype "unspecified")
(uuid "8ce0a254-6994-4377-9224-16722c7801b8")
)
(pad "30" smd rect
(at 0.25 -4.1 90)
(size 0.27 1.2)
(pad "30" smd oval
(at 0.25 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 46 "unconnected-(U4-PA9-Pad30)")
(pinfunction "PA9")
(pintype "unspecified")
(uuid "d3ebe670-7847-4127-b5c4-19f171eb81c9")
)
(pad "31" smd rect
(at -0.25 -4.1 90)
(size 0.27 1.2)
(pad "31" smd oval
(at -0.25 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 35 "unconnected-(U4-PA10-Pad31)")
(pinfunction "PA10")
(pintype "unspecified")
(uuid "8b8da939-4024-4e32-96e4-fc5543e3e18f")
)
(pad "32" smd rect
(at -0.75 -4.1 90)
(size 0.27 1.2)
(pad "32" smd oval
(at -0.75 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 48 "unconnected-(U4-PA11-Pad32)")
(pinfunction "PA11")
(pintype "unspecified")
(uuid "dd72a79a-5424-43d2-ac5b-4cf6f1255fdf")
)
(pad "33" smd rect
(at -1.25 -4.1 90)
(size 0.27 1.2)
(pad "33" smd oval
(at -1.25 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 38 "unconnected-(U4-PA12-Pad33)")
(pinfunction "PA12")
(pintype "unspecified")
(uuid "91063092-82f4-400e-843e-698551e2e924")
)
(pad "34" smd rect
(at -1.75 -4.1 90)
(size 0.27 1.2)
(pad "34" smd oval
(at -1.75 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 61 "Net-(U4-PA13)")
(pinfunction "PA13")
(pintype "unspecified")
(uuid "c2b2b7fd-8da9-43c3-8295-385616c36888")
)
(pad "35" smd rect
(at -2.25 -4.1 90)
(size 0.27 1.2)
(pad "35" smd oval
(at -2.25 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 1 "GND")
(pinfunction "VSS_2")
(pintype "unspecified")
(uuid "24317dc7-634e-4222-9310-d4bc9f967cb0")
)
(pad "36" smd rect
(at -2.75 -4.1 90)
(size 0.27 1.2)
(pad "36" smd oval
(at -2.75 -4.25 90)
(size 0.27 1.5)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 2 "+3V0")
(pinfunction "VDD_2")
(pintype "unspecified")
(uuid "e8ed6ff4-de5a-4f85-a401-8ebfda5f8f0f")
)
(pad "37" smd rect
(at -4.1 -2.75 90)
(size 1.2 0.27)
(pad "37" smd oval
(at -4.25 -2.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 60 "Net-(U4-PA14)")
(pinfunction "PA14")
(pintype "unspecified")
(uuid "1f55ad4f-182f-47cf-8b85-346142f98316")
)
(pad "38" smd rect
(at -4.1 -2.25 90)
(size 1.2 0.27)
(pad "38" smd oval
(at -4.25 -2.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 29 "unconnected-(U4-PA15-Pad38)")
(pinfunction "PA15")
(pintype "unspecified")
(uuid "677e4bfa-e584-4c60-a5d8-fd2f7affc275")
)
(pad "39" smd rect
(at -4.1 -1.75 90)
(size 1.2 0.27)
(pad "39" smd oval
(at -4.25 -1.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 41 "unconnected-(U4-PB3-Pad39)")
(pinfunction "PB3")
(pintype "unspecified")
(uuid "a922c2b2-2a9f-481b-8b51-9ce0bd8c5516")
)
(pad "40" smd rect
(at -4.1 -1.25 90)
(size 1.2 0.27)
(pad "40" smd oval
(at -4.25 -1.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 44 "unconnected-(U4-PB4-Pad40)")
(pinfunction "PB4")
(pintype "unspecified")
(uuid "e2c35414-4f6d-4fc0-810b-348e9a9ad944")
)
(pad "41" smd rect
(at -4.1 -0.75 90)
(size 1.2 0.27)
(pad "41" smd oval
(at -4.25 -0.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 27 "unconnected-(U4-PB5-Pad41)")
(pinfunction "PB5")
(pintype "unspecified")
(uuid "21cc3b59-48b9-4a5b-8d0e-038d18defcfd")
)
(pad "42" smd rect
(at -4.1 -0.25 90)
(size 1.2 0.27)
(pad "42" smd oval
(at -4.25 -0.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 52 "unconnected-(U4-PB6-Pad42)")
(pinfunction "PB6")
(pintype "unspecified")
(uuid "c4edd4f7-b058-4939-af04-b85f06692d7e")
)
(pad "43" smd rect
(at -4.1 0.25 90)
(size 1.2 0.27)
(pad "43" smd oval
(at -4.25 0.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 37 "unconnected-(U4-PB7-Pad43)")
(pinfunction "PB7")
(pintype "unspecified")
(uuid "7da691e2-6a88-420a-bb2d-69849698cf32")
)
(pad "44" smd rect
(at -4.1 0.75 90)
(size 1.2 0.27)
(pad "44" smd oval
(at -4.25 0.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 12 "Net-(U4-BOOT0)")
(pinfunction "BOOT0")
(pintype "unspecified")
(uuid "1c05f1dd-5aea-4c70-8aa3-fb41e5f52f8e")
)
(pad "45" smd rect
(at -4.1 1.25 90)
(size 1.2 0.27)
(pad "45" smd oval
(at -4.25 1.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 54 "unconnected-(U4-PB8-Pad45)")
(pinfunction "PB8")
(pintype "unspecified")
(uuid "a448b535-f251-490e-81b3-6788b9f23dec")
)
(pad "46" smd rect
(at -4.1 1.75 90)
(size 1.2 0.27)
(pad "46" smd oval
(at -4.25 1.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 47 "unconnected-(U4-PB9-Pad46)")
(pinfunction "PB9")
(pintype "unspecified")
(uuid "d6136b25-93e2-4c71-a1c1-59cce16df0a7")
)
(pad "47" smd rect
(at -4.1 2.25 90)
(size 1.2 0.27)
(pad "47" smd oval
(at -4.25 2.25 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 1 "GND")
(pinfunction "VSS_3")
(pintype "unspecified")
(uuid "6b6a454c-46d5-4148-817b-94b9f32762d4")
)
(pad "48" smd rect
(at -4.1 2.75 90)
(size 1.2 0.27)
(pad "48" smd oval
(at -4.25 2.75 90)
(size 1.5 0.27)
(layers "F.Cu" "F.Mask" "F.Paste")
(net 2 "+3V0")
(pinfunction "VDD_3")
@ -24721,19 +24722,6 @@
(justify left bottom)
)
)
(gr_text "BEFORE RE-ORDERING:\n- fix routing to MCU; footprint was changed\n- fix vtext\n- SPI NSI\n- LEDs?\n- change your god damn test pins - remove if no more needed\n- remove button outlines\n- SPI speed stuck at 2mHZ - differential routing?\n- LCD backlight MOSFTER\n- test to see if sleep mode is accurate to datasheet - screen responds in sleep mode, which is sus\n- add mosfet to LED VDD if above is too sus"
(at 135.087495 79.340705 0)
(layer "Cmts.User" knockout)
(uuid "f62f4e68-b57a-4b61-ac63-ac1136d71720")
(effects
(font
(size 1.5 1.5)
(thickness 0.3)
(bold yes)
)
(justify left bottom)
)
)
(segment
(start 182.407094 90.00238)
(end 187.403529 94.998815)
@ -26584,11 +26572,11 @@
)
(segment
(start 177.240878 120.284125)
(end 176.090878 120.284125)
(end 176.240878 120.284125)
(width 0.25)
(layer "F.Cu")
(net 16)
(uuid "be0e08ba-2b96-42b8-80e0-f297a07d0120")
(uuid "efa4a209-6ef1-41c5-aac2-a1bbf3aa6436")
)
(segment
(start 202.951133 109.165534)

View File

@ -1,7 +1,7 @@
{
"board": {
"active_layer": 7,
"active_layer_preset": "",
"active_layer": 0,
"active_layer_preset": "Back Layers",
"auto_track_width": true,
"hidden_netclasses": [],
"hidden_nets": [],
@ -48,7 +48,7 @@
"conflict_shadows",
"shapes"
],
"visible_layers": "00000000_00000000_00000008_82082223",
"visible_layers": "00000000_00000000_00000002_2200888c",
"zone_display_mode": 1
},
"git": {

View File

@ -108,7 +108,6 @@
"solder_mask_bridge": "error",
"starved_thermal": "error",
"text_height": "warning",
"text_on_edge_cuts": "error",
"text_thickness": "warning",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",

View File

@ -1 +0,0 @@
{"hostname":"indigosDesktop","username":"indigo"}

View File

@ -1,187 +1,256 @@
context
file
continue
continue
set exception-verbose on
continue
exit
file
quit
quit
context
next
quit
nexti
nexti
continue
nexti
monitor reset halt
context
continue
next
next
next
next
next
load
context
nexti
continue
monitor reset halt
set mem inaccessible-by-default off
context
load
context
nexti
load
context
b main
c
load
context
nexti
gdb memory_map enable
exit()
exit
context
start
context
print wait_time
quit
target extended-remote | \
openocd -c "gdb port pipe; log_output openocd.log"
target extended-remote | openocd -c "gdb port pipe; log_output openocd.log"
exit()
exit
quit
target extended-remote localhost:3333
monitor reset halt
load
context
where
list _stack_init
list _stack_init()
set_enable_virt2phys
load
b HAL_EXTI_RegisterCallback
p 0x08000070
p main
nexti
c
quit
load
context
registers
info reg
show debug monitor
show debug
show debug monitor
show debug arm
set debug arm on
show debug arm
c
print time
b st7735.c:104
load
c
quit
b st7735.c:102
c
load
c
c
c
c
c
c
c
c
quit
load
c
print time
quit
load
c
print time
quit
load
c
quit
quit
reload
load
c
context
nexti
load
info reg
target sim
monitor shutdown
monitor shutdown
exit
file build/stm32f1_buisnesscard_v1.elf
load
monitor reset run
exit
quit
nexti
next
nexti
c
nexti
continue
nexti
c
quit
nexti
next
break main.c:120
r
break main.c:82
c
exit()
quit
c
next
quit
load
start
quit
start
c
target extended-remote | \
openocd -c "gdb port pipe; log_output openocd.log"
target extended-remote | openocd -c "gdb port pipe; log_output openocd.log"
exit
tar ext :3333
b HAL_GPIO_EXTI_Callback
b HAL_TIM_PeriodElapsedCallback
load
c
quit
load
c
quit
load
c
f 2
f 4
f 5
context
f 6
context
f 5
context
quit
load
c
f 2
f 3
context
quit
load
context
c
c
print htim
print *htim
c
tar ext :3333
info b
d b
d
d
b HAL_TIM_PeriodElapsedCallback
b HAL_GPIO_EXTI_Callback
c
c
restart
run
c
p time
c
quit
hu
hi
load
c
p time
quit
load
c
p time
quit
load
c
p time
quit
quit
c
load
c
p time
quit
c
load
c
quit
quit
load
c
b st7735.c:320
b ST7735.c:320
b ST7735.c:320
c
load
c
quit
exit
exit
quit
exittar ext localhost 3333
tar ext localhost 3333
target extended-remote 3333
target extended-remote localhost:3333
exit
quit
quit
quit
b mandelbrot.c:102
b ST7735.c:320
load
c
c
print cam
c
print cam
p time
b ST7735_DrawImage
c
p x
p y
c
quit
load
c
p time
b ST7735_DrawImage
c
p x
x y
p y
p x
c
f 4
c
quit
load
c
load
b ST7735_DrawImage
c
p x
p y
c
p x
p y
p h
p y
p h
quit
load
c
p time
c
f 2
f 1
context
c
print cam
step
next
next
print i_offset
print r_offset
print *cam
next
print *cam
next
print cam
print *cam
next
print cam
c
print cam
quit
load
c
p itme
p time
c
c
print uwTick
c
print tickstart
print wait
quit
load
c
c
c
quit
load
c
quit
quit
load
c
load
c
quit
load
c
quit
load
c
p time
c
quit
load
c
c
quit
load
c
quitr
quit
load
c
quit
c
load
c
c
load
c
p time
quit
load
c
p time
quit
c
p itme
p time
quit
load
c
p time
quit
c
qquit
quit
load
c
p itme
p time
c
quit
load
c
quit
load
c
p itme
p time
quit
load
quit
load
c
quit
quit
c
load
c
b 153
b mandelbrot.c:153
c
p colorscheme
quit
load
c
quit

View File

@ -0,0 +1,15 @@
#pragma once
#include <signal.h>
#include "main.h"
static float time __attribute__((used));
__attribute__((always_inline)) void static inline benchmark_start() {
TIM4->CNT = 0;
TIM4->CR1 |= TIM_CR1_CEN;
}
__attribute__((always_inline)) void static inline benchmark_stop() {
TIM4->CR1 ^= TIM_CR1_CEN;
time = (float)(TIM4->CNT + 1) * (TIM4->PSC + 1) / HAL_RCC_GetSysClockFreq();
__BKPT();
}

View File

@ -21,8 +21,10 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include "st7735.h"
#include "mandelbrot.h"
#include "benchmark.h"
//#include "mandelbrot.h"
/* USER CODE END Includes */
@ -46,6 +48,7 @@
SPI_HandleTypeDef hspi1;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim4;
/* USER CODE BEGIN PV */
@ -56,12 +59,14 @@ void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
static void MX_TIM2_Init(void);
static void MX_TIM4_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
//when idling, vreg stop mode, low power mode stop
//when sleeping, vreg stop mode, low power mode standby (RTC alarm)
@ -143,12 +148,16 @@ int main(void)
MX_GPIO_Init();
MX_SPI1_Init();
MX_TIM2_Init();
MX_TIM4_Init();
/* USER CODE BEGIN 2 */
ST7735_Init();
ST7735_InvertColors(false);
ST7735_FillScreenFast(ST7735_MAGENTA);
//ST7735_FillScreenFast(ST7735_MAGENTA);
//HAL_GPIO_EXTI_Callback(0xff);
benchmark_start();
draw_mandelbrot(button_pressed);
benchmark_stop();
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
@ -168,9 +177,9 @@ int main(void)
{
//later we'll impliment menu
if(button_event) {
HAL_ResumeTick();
HAL_TIM_Base_Stop_IT(&htim2);
draw_mandelbrot(button_pressed);
//__HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_UPDATE);
HAL_SuspendTick();
__HAL_TIM_SET_COUNTER(&htim2, 0);
HAL_TIM_Base_Start_IT(&htim2);
@ -186,6 +195,7 @@ int main(void)
ST7735_wake();
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
@ -312,6 +322,51 @@ static void MX_TIM2_Init(void)
}
/**
* @brief TIM4 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM4_Init(void)
{
/* USER CODE BEGIN TIM4_Init 0 */
/* USER CODE END TIM4_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM4_Init 1 */
/* USER CODE END TIM4_Init 1 */
htim4.Instance = TIM4;
htim4.Init.Prescaler = 4882;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 0xffff;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM4_Init 2 */
/* USER CODE END TIM4_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None

View File

@ -1,6 +1,7 @@
#include <stdint.h>
#include "mandelbrot.h"
#include "st7735.h"
#include "benchmark.h"
#define RES_X 160
#define RES_Y 80
@ -30,34 +31,33 @@
#define CAM_DEF_MIN_R -1
#define CAM_DEF_MAX_R 1
int state = MANDELBROT; //TODO change to help once developed
struct camera {
double min_r, min_i, max_r, max_i;
};
#undef SHIP
enum VIEW_MODES { VIEW_UNINIT, VIEW_MANDREL, VIEW_SHIP };
//TODO optimize the FUCK outta this, it's ass
#ifdef SHIP
//BGR coloring, b:5 x g:6 x r:5
inline uint16_t get_color(int i) {
if(i == 0) || (i == ITERS) return 0;
//return (2*(i - (128)+0x1f) << (5+6); FIXME
void init_colorscheme_mandrel(uint16_t *scheme) {
uint16_t *tc = scheme;
for(unsigned int i = 0; i < ITERS; i++) {
if((i == 0) || (i == ITERS)) *tc = 0;
else if(i < 128) *tc = (((((i - 64) << 2)+0x1f) & 0x1f) | (((((i - 128) << 1)+0x1f) & 0x1f) << (5+6)));
else *tc = (-2*(i - 128)+0x1f) & 0xff;
*tc = (*tc << 8) | (*tc >> 8); //convert to little endian
tc++;
}
}
#else
uint16_t get_color(int i);
inline uint16_t get_color(int i) {
if((i == 0) || (i == ITERS)) return 0;
//return(ST7735_BLUE);
//TODO convert multiplication to shifts
if(i < 128) return (((4*(i - 64)+0x1f) & 0x1f) | (((2*(i - 128)+0x1f) & 0x1f) << (5+6)));
return (-2*(i - 128)+0x1f) & 0xff;
}
#endif
void shift_cam(struct camera *cam, double step_r, double step_i) {
void init_colorscheme_ship(uint16_t *scheme) {
uint16_t *tc = scheme;
for(unsigned int i = 0; i < ITERS; i++) {
if((i == 0) || (i == ITERS)) *tc = 0;
else *tc = (((i - (128)) << 1)+0x1f) << (5+6);
tc++;
}
}
void cam_shift(struct camera *cam, double step_r, double step_i) {
double i_offset = (cam->max_i - cam->min_i) * step_i;
double r_offset = (cam->max_r - cam->min_r) * step_r;
cam->min_i += i_offset;
@ -66,7 +66,7 @@ void shift_cam(struct camera *cam, double step_r, double step_i) {
cam->max_r += r_offset;
}
void zoom_cam(struct camera *cam, double zoom) {
void cam_zoom(struct camera *cam, double zoom) {
double i_scale = (cam->max_i - cam->min_i) * zoom;
double r_scale = (cam->max_r - cam->min_r) * zoom;
cam->min_i += i_scale;
@ -75,7 +75,47 @@ void zoom_cam(struct camera *cam, double zoom) {
cam->max_r -= r_scale;
}
//TODO look into border tracing; this is too slow
void render_mandelbrot(uint16_t *framebuffer, uint16_t *colorscheme, struct camera cam, bool half) {
int32_t scale_i = DOUBLE_TO_FIXED((cam.max_i - cam.min_i) / (double)RES_Y);
int32_t scale_r = DOUBLE_TO_FIXED((cam.max_r - cam.min_r) / (double)RES_X);
int32_t c_i = DOUBLE_TO_FIXED(half ? ((cam.max_i - cam.min_i) / 2) + cam.min_i : (cam.max_i));
int32_t c_r, z_i, z_r, zn_r;
int32_t z_r_2, z_i_2;
size_t fb_index = 0;
int i;
for(int y = 0; y < (RES_Y/2); y++) {
c_r = DOUBLE_TO_FIXED(cam.min_r);
for(int x = 0; x < RES_X; x++) {
z_i = 0;
z_r = 0;
for(i = 0; i < ITERS; i++) {
z_r_2 = FIXED_MULTIPLY(z_r, z_r);
z_i_2 = FIXED_MULTIPLY(z_i, z_i);
zn_r = z_r_2 - z_i_2 + c_r;
//z_i = abs(FIXED_MULTIPLY((DOUBLE_TO_FIXED(2)), (FIXED_MULTIPLY(z_r, z_i)))) + c_i;
z_i = (FIXED_MULTIPLY(z_r, z_i) << 1) + c_i;
z_r = zn_r;
if(z_i_2 + z_r_2 > INFTY_SQR_FIXED) break;
}
framebuffer[fb_index++] = colorscheme[i];
// ST7735_DrawPixel(x, y, colorscheme[i]);
c_r += scale_r;
}
c_i -= scale_i;
}
}
//TODO rename
void draw_mandelbrot(int key_pressed) {
uint16_t framebuffer[(RES_X * RES_Y) / 2];
//program flow is awful atm becuase I was planning something different; will be improved soon.
static struct camera cam = {
.min_r = CAM_DEF_MIN_R,
.max_r = CAM_DEF_MAX_R,
@ -83,62 +123,38 @@ void draw_mandelbrot(int key_pressed) {
.max_i = ((double)RES_Y / RES_X) * CAM_DEF_MAX_R,
};
static int view_mode = VIEW_UNINIT;
static uint16_t colorscheme[ITERS];
if(view_mode == VIEW_UNINIT) {
view_mode = VIEW_MANDREL;
init_colorscheme_mandrel(colorscheme);
}
switch(key_pressed) {
case KEYCODE_UP:
shift_cam(&cam, 0, STEP_SIZE);
cam_shift(&cam, 0, STEP_SIZE);
break;
case KEYCODE_DOWN:
shift_cam(&cam, 0, -STEP_SIZE);
cam_shift(&cam, 0, -STEP_SIZE);
break;
case KEYCODE_RIGHT:
shift_cam(&cam, -STEP_SIZE, 0);
cam_shift(&cam, -STEP_SIZE, 0);
break;
case KEYCODE_LEFT:
shift_cam(&cam, STEP_SIZE, 0);
cam_shift(&cam, STEP_SIZE, 0);
break;
case KEYCODE_A:
zoom_cam(&cam, ZOOM_SIZE);
cam_zoom(&cam, ZOOM_SIZE);
break;
case KEYCODE_B:
zoom_cam(&cam, -ZOOM_SIZE);
cam_zoom(&cam, -ZOOM_SIZE);
break;
default:
}
{
int32_t scale_i = DOUBLE_TO_FIXED((cam.max_i - cam.min_i) / (double)RES_Y);
int32_t scale_r = DOUBLE_TO_FIXED((cam.max_r - cam.min_r) / (double)RES_X);
int32_t c_i = DOUBLE_TO_FIXED(cam.max_i);
int32_t c_r, z_i, z_r, zn_i, zn_r;
int32_t z_r_2, z_i_2;
int i;
for(int y = 0; y < RES_Y; y++) {
c_r = DOUBLE_TO_FIXED(cam.min_r);
for(int x = 0; x < RES_X; x++) {
z_i = 0;
z_r = 0;
//TODO optimize
for(i = 0; i < ITERS; i++) {
z_r_2 = FIXED_MULTIPLY(z_r, z_r);
z_i_2 = FIXED_MULTIPLY(z_i, z_i);
zn_r = z_r_2 - z_i_2 + c_r;
#ifdef SHIP
zn_i = abs(FIXED_MULTIPLY((DOUBLE_TO_FIXED(2)), (FIXED_MULTIPLY(z_r, z_i)))) + c_i;
#else
zn_i = (FIXED_MULTIPLY((DOUBLE_TO_FIXED(2)), (FIXED_MULTIPLY(z_r, z_i)))) + c_i;
#endif
z_i = zn_i;
z_r = zn_r;
if(z_i_2 + z_r_2 > INFTY_SQR_FIXED) break;
}
ST7735_DrawPixel(x, y, get_color(i));
c_r += scale_r;
}
c_i -= scale_i;
}
}
render_mandelbrot(framebuffer, colorscheme, cam, false);
ST7735_DrawImage(0, 0, ST7735_WIDTH, (ST7735_HEIGHT / 2), framebuffer);
render_mandelbrot(framebuffer, colorscheme, cam, true);
ST7735_DrawImage(0, (ST7735_HEIGHT / 2), ST7735_WIDTH, (ST7735_HEIGHT / 2), framebuffer);
// ST7735_DrawImage(0, 0, ST7735_WIDTH - 1, ST7735_HEIGHT - 1, (uint16_t *)0x80000000);
}

View File

@ -1,7 +1,11 @@
/* vim: set ai et ts=4 sw=4: */
#include <math.h>
#include "main.h"
#include "stm32f103xb.h"
#include "stm32f1xx_hal.h"
#include "st7735.h"
#include "malloc.h"
#include "stm32f1xx_hal_spi.h"
#include "string.h"
#define DELAY 0x80
@ -85,6 +89,17 @@ static const uint8_t
ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay
100 }; // 100 ms delay
//#define ST7735_WriteData(buff, buff_size) spi_write_data((buff), (buff_size))
//temporary to test def
static void spi_write_data(uint8_t *data, uint16_t size) {
ST7735_DC_GPIO_Port->ODR |= ST7735_DC_Pin;
for(uint16_t i = 0; i < size; i++) {
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = *(data++);
}
}
static void ST7735_Select() {
HAL_GPIO_WritePin(ST7735_CS_GPIO_Port, ST7735_CS_Pin, GPIO_PIN_RESET);
}

View File

@ -166,7 +166,17 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
/* USER CODE BEGIN TIM2_MspInit 1 */
/* USER CODE END TIM2_MspInit 1 */
}
else if(htim_base->Instance==TIM4)
{
/* USER CODE BEGIN TIM4_MspInit 0 */
/* USER CODE END TIM4_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_TIM4_CLK_ENABLE();
/* USER CODE BEGIN TIM4_MspInit 1 */
/* USER CODE END TIM4_MspInit 1 */
}
}
@ -193,6 +203,17 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
/* USER CODE END TIM2_MspDeInit 1 */
}
else if(htim_base->Instance==TIM4)
{
/* USER CODE BEGIN TIM4_MspDeInit 0 */
/* USER CODE END TIM4_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM4_CLK_DISABLE();
/* USER CODE BEGIN TIM4_MspDeInit 1 */
/* USER CODE END TIM4_MspDeInit 1 */
}
}

Some files were not shown because too many files have changed in this diff Show More