Skip to content

Instantly share code, notes, and snippets.

@Measter
Last active June 2, 2020 15:46
Show Gist options
  • Save Measter/c0ffa1b10e1e5a8a009ab72722a43610 to your computer and use it in GitHub Desktop.
Save Measter/c0ffa1b10e1e5a8a009ab72722a43610 to your computer and use it in GitHub Desktop.
StrongIO Bench
#include <Arduino.h>
void setup() {
// LED pin will act as a bookend to the IO tests.
DDRB |= (1 << PB5); // Configure builtin LED pin for output.
__asm__ volatile ("nop");
PORTB |= (1 << PB5); // Set LED pin high.
volatile uint8_t digital_data;
pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(4, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(12, INPUT);
digital_data = digitalRead(0);
digital_data = digitalRead(1);
digital_data = digitalRead(2);
digital_data = digitalRead(4);
digital_data = digitalRead(7);
digital_data = digitalRead(8);
digital_data = digitalRead(12);
PORTB &= !(1 << PB5); // Set LED pin low.
PORTB |= (1 << PB5); // Set LED pin high.
analogWrite(5, 128);
analogWrite(6, 128);
analogWrite(9, 128);
analogWrite(10, 128);
analogWrite(3, 128);
analogWrite(11, 128);
PORTB &= !(1 << PB5); // Set LED pin low.
}
void loop() {
}
#include <Arduino.h>
void setup() {
// LED pin will act as a bookend to the IO tests.
DDRB |= (1 << PB5); // Configure builtin LED pin for output.
__asm__ volatile ("nop");
PORTB |= (1 << PB5); // Set LED pin high.
volatile uint8_t digital_data;
// Set pins D0 to D7 to output.
DDRD |= 0xFF;
// Set pins D8 to D12 to output.
DDRB |= 0x1F;
__asm__ volatile ("nop");
// Reading pins D0 to D7
digital_data = (PORTD & PD0) != 0;
digital_data = (PORTD & PD1) != 0;
digital_data = (PORTD & PD2) != 0;
digital_data = (PORTD & PD4) != 0;
digital_data = (PORTD & PD7) != 0;
// Reading pins D8 and D12
digital_data = (PORTB & PB0) != 0;
digital_data = (PORTB & PB4) != 0;
PORTB &= !(1 << PB5); // Set LED pin low.
PORTB |= (1 << PB5); // Set LED pin high.
// Connect Timer0 to D5 and D6
TCCR0A |= ((1 << COM0A1) | (1 << COM0B1));
// Connect Timer1 to D9 and D10
TCCR1A |= ((1 << COM1A1) | (1 << COM1B1));
// Connect Timer2 to D3 and D11
TCCR2A |= ((1 << COM2A1) | (1 << COM2B1));
// Set duty for all 6 channels
OCR0A = 128;
OCR0B = 128;
OCR1AL = 128;
OCR1BL = 128;
OCR2A = 128;
OCR2B = 128;
PORTB &= !(1 << PB5); // Set LED pin low.
}
void loop() {
}
#include <Arduino.h>
#include "strong_io.h"
void setup() {
// LED pin will act as a bookend to the IO tests.
DDRB |= (1 << PB5); // Configure builtin LED pin for output.
__asm__ volatile ("nop");
PORTB |= (1 << PB5); // Set LED pin high.
volatile PinState digital_data;
IO::DigitalIn<Pin::D0> pin0;
IO::DigitalIn<Pin::D1> pin1;
IO::DigitalIn<Pin::D2> pin2;
IO::DigitalIn<Pin::D4> pin4;
IO::DigitalIn<Pin::D7> pin7;
IO::DigitalIn<Pin::D8> pin8;
IO::DigitalIn<Pin::D12> pin12;
digital_data = pin0.read();
digital_data = pin1.read();
digital_data = pin2.read();
digital_data = pin4.read();
digital_data = pin7.read();
digital_data = pin8.read();
digital_data = pin12.read();
PORTB &= !(1 << PB5); // Set LED pin low.
PORTB |= (1 << PB5); // Set LED pin high.
IO::PWM<Pin::D5> pin5;
IO::PWM<Pin::D6> pin6;
IO::PWM<Pin::D9> pin9;
IO::PWM<Pin::D10> pin10;
IO::PWM<Pin::D3> pin3;
IO::PWM<Pin::D11> pin11;
pin5.set_duty(128);
pin6.set_duty(128);
pin9.set_duty(128);
pin10.set_duty(128);
pin11.set_duty(128);
pin3.set_duty(128);
PORTB &= !(1 << PB5); // Set LED pin low.
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment