-
Notifications
You must be signed in to change notification settings - Fork 178
An attempt at mostly complete avr support #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
philocalyst
wants to merge
23
commits into
ZigEmbeddedGroup:main
Choose a base branch
from
philocalyst:avr-avr-avr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
edd2d4b
build.zig: Register ATtiny port
philocalyst 78fbd15
attiny: Add package manifest and README
philocalyst eeebd57
attiny: Define chip targets
philocalyst 98206ce
attiny: Add small board definitions
philocalyst 115ef2a
attiny: Add ATtiny84 and ATtiny85 HAL roots
philocalyst be2b497
attiny85: Add register and GPIO helpers
philocalyst 6822449
attiny85: Add timer helpers
philocalyst 0c2e2d4
attiny85: Add ADC watchdog and sleep helpers
philocalyst d08f458
attiny85: Add PCINT EEPROM and PROGMEM helpers
philocalyst c9b9d5b
attiny1634: Add HAL root and registers
philocalyst be5a96f
attiny1634: Add GPIO and PWM helpers
philocalyst e02cd3e
attiny1634: Add ADC WDT PCINT and EEPROM helpers
philocalyst 00003d6
attiny1616: Add HAL root and registers
philocalyst 3ae77f7
attiny1616: Add GPIO clock and PCINT helpers
philocalyst e2a39a7
attiny1616: Add TCA0 and RTC PIT helpers
philocalyst a344d0b
attiny1616: Add ADC WDT and EEPROM helpers
philocalyst f8a1743
examples: Add ATtiny blinky examples
philocalyst a297856
examples: Add ATtiny1634 PWM ADC example
philocalyst 2a3d780
examples: Add ATtiny1616 TCA RTC example
philocalyst 0115759
attiny: Use snake case HAL helper names
philocalyst 930aa39
new zig fixes
philocalyst 70e31a4
ci fixes???
philocalyst 306c438
Revert tool/build changes per review
philocalyst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| const microzig = @import("microzig"); | ||
| const hal = microzig.hal; | ||
|
|
||
| const pwm_cool = hal.gpio.pin(.b, 0); | ||
| const pwm_warm = hal.gpio.pin(.b, 1); | ||
| const aux_led = hal.gpio.pin(.b, 5); | ||
| const switch_pin = hal.gpio.pin(.a, 5); | ||
| const Ramp = hal.progmem.Table(u8, 4, .{ 1, 4, 16, 64 }); | ||
|
|
||
| pub fn main() void { | ||
| hal.clock.use_default20_m_hz_div2(); | ||
|
|
||
| pwm_cool.set_direction(.output); | ||
| pwm_warm.set_direction(.output); | ||
| aux_led.set_direction(.output); | ||
| hal.pcint.configure(switch_pin, true, .both_edges); | ||
|
|
||
| hal.tca0.configure_pwm(.{ | ||
| .top = 255, | ||
| .compare0 = 48, | ||
| .compare1 = 96, | ||
| .enable_compare0 = true, | ||
| .enable_compare1 = true, | ||
| .waveform = .dual_slope_bottom, | ||
| .clock = .div1, | ||
| }); | ||
|
|
||
| hal.rtc_pit.configure(.cycles512, true); | ||
| hal.adc.configure(.{ | ||
| .channel = .internal_reference, | ||
| .reference = .vdd, | ||
| .sample_count = .samples4, | ||
| .prescaler = .div16, | ||
| .initial_delay = .cycles16, | ||
| .sample_capacitance = true, | ||
| .freerun = true, | ||
| .run_standby = true, | ||
| }); | ||
| hal.adc.enable_result_ready_interrupt(); | ||
| hal.adc.start(); | ||
| hal.watchdog.reset(); | ||
|
|
||
| const saved_level = hal.eeprom.read_byte(.from_int(0)); | ||
| const ramp_level = Ramp.get(1); | ||
| _ = saved_level; | ||
| _ = ramp_level; | ||
|
|
||
| while (true) { | ||
| nop(); | ||
| } | ||
| } | ||
|
|
||
| inline fn nop() void { | ||
| asm volatile ("nop"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| const microzig = @import("microzig"); | ||
| const hal = microzig.hal; | ||
|
|
||
| const ch1_pwm = hal.gpio.pin(.b, 3); | ||
| const ch2_pwm = hal.gpio.pin(.a, 6); | ||
| const fet_pwm = hal.gpio.pin(.c, 0); | ||
| const voltage = hal.gpio.pin(.b, 1); | ||
| const Gamma = hal.progmem.Table(u8, 4, .{ 0, 8, 32, 255 }); | ||
|
|
||
| pub fn main() void { | ||
| ch1_pwm.set_direction(.output); | ||
| ch2_pwm.set_direction(.output); | ||
| fet_pwm.set_direction(.output); | ||
| voltage.set_direction(.input); | ||
|
|
||
| hal.timer1.configure_phase_correct_dynamic(.{ .top = 255, .prescaler = .clk_1 }); | ||
| hal.timer1.set_compare_a(96); | ||
| hal.timer1.set_compare_b(64); | ||
|
|
||
| hal.timer0.configure_phase_correct_pwm_a(.clk_1); | ||
| hal.timer0.set_compare_a(32); | ||
|
|
||
| hal.adc.configure_internal1v1(.adc6, .div64); | ||
| hal.adc.start(); | ||
| hal.watchdog.reset(); | ||
| hal.watchdog.configure(.interrupt, .ms16); | ||
|
|
||
| const saved_level = hal.eeprom.read_byte(hal.eeprom.address(0)); | ||
| const gamma_level = Gamma.get(2); | ||
| _ = saved_level; | ||
| _ = gamma_level; | ||
|
|
||
| while (true) { | ||
| nop(); | ||
| } | ||
| } | ||
|
|
||
| inline fn nop() void { | ||
| asm volatile ("nop"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| const std = @import("std"); | ||
| const microzig = @import("microzig"); | ||
| const gpio = microzig.hal.gpio; | ||
|
|
||
| // ATtiny84: use PA0 as the LED pin | ||
| const led_pin = gpio.pin(.a, 0); | ||
|
|
||
| pub fn main() void { | ||
| led_pin.set_direction(.output); | ||
|
|
||
| while (true) { | ||
| busy_sleep(20_000); | ||
| led_pin.toggle(); | ||
| } | ||
| } | ||
|
|
||
| pub fn busy_sleep(comptime limit: comptime_int) void { | ||
| if (limit <= 0) @compileError("limit must be non-negative!"); | ||
|
|
||
| comptime var bits = 0; | ||
| inline while ((1 << bits) <= limit) { | ||
| bits += 1; | ||
| } | ||
|
|
||
| const I = std.meta.Int(.unsigned, bits); | ||
|
|
||
| var i: I = 0; | ||
| while (i < limit) : (i += 1) { | ||
| std.mem.doNotOptimizeAway(i); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| const std = @import("std"); | ||
| const microzig = @import("microzig"); | ||
| const gpio = microzig.hal.gpio; | ||
|
|
||
| const led_pin = gpio.pin(.b, 1); | ||
|
|
||
| pub const microzig_options: microzig.Options = .{ | ||
| .interrupts = .{ | ||
| .INT0 = &my_int0_handler, | ||
| }, | ||
| }; | ||
|
|
||
| fn my_int0_handler() callconv(.avr_signal) void { | ||
| led_pin.toggle(); | ||
| } | ||
|
|
||
| pub fn main() void { | ||
| led_pin.set_direction(.output); | ||
|
|
||
| while (true) { | ||
| std.mem.doNotOptimizeAway({}); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,9 @@ | |
| ## Supported Chips | ||
|
|
||
| - ATtiny85 | ||
| - ATtiny84 | ||
| - ATtiny1634 | ||
| - ATtiny1616 | ||
|
|
||
| ## FYI: LLVM issues | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| pub const chip = @import("chip"); | ||
|
|
||
| pub const clock_frequencies = .{ | ||
| .cpu = 8_000_000, | ||
| }; | ||
|
|
||
| pub const pin_map = .{ | ||
| .D0 = "PB0", | ||
| .D1 = "PB1", | ||
| .D2 = "PB2", | ||
| // Built-in LED on D1 (PB1) | ||
| .LED = "PB1", | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| pub const chip = @import("chip"); | ||
|
|
||
| pub const clock_frequencies = .{ | ||
| .cpu = 16_500_000, | ||
| }; | ||
|
|
||
| pub const pin_map = .{ | ||
| // Digispark pin numbering maps to PORTB | ||
| .P0 = "PB0", | ||
| .P1 = "PB1", | ||
| .P2 = "PB2", | ||
| .P3 = "PB3", | ||
| .P4 = "PB4", | ||
| .P5 = "PB5", | ||
| // Built-in LED on P1 (PB1) | ||
| .LED = "PB1", | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| pub const registers = @import("attiny1616/registers.zig"); | ||
| pub const gpio = @import("attiny1616/gpio.zig"); | ||
| pub const clock = @import("attiny1616/clock.zig"); | ||
| pub const tca0 = @import("attiny1616/tca0.zig"); | ||
| pub const rtc_pit = @import("attiny1616/rtc_pit.zig"); | ||
| pub const adc = @import("attiny1616/adc.zig"); | ||
| pub const pcint = @import("attiny1616/pcint.zig"); | ||
| pub const watchdog = @import("attiny1616/watchdog.zig"); | ||
| pub const eeprom = @import("attiny1616/eeprom.zig"); | ||
| pub const progmem = @import("attiny85/progmem.zig"); | ||
|
|
||
| pub const memory = struct { | ||
| pub const flash_size = 16 * 1024; | ||
| pub const eeprom_size = 256; | ||
| pub const sram_size = 2048; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this put 20'000 increment instructions rather than a loop?