From: Manfred Steiner Date: Wed, 24 Jul 2024 17:03:22 +0000 (+0200) Subject: ... X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=e8cd05501a87a628cd396dfd0619993a23d4a6c9;p=nano-x-base.git ... --- diff --git a/kicad/dist/v1a/README.md b/kicad/dist/v1a/README.md index 82563fd..4f8190b 100644 --- a/kicad/dist/v1a/README.md +++ b/kicad/dist/v1a/README.md @@ -77,12 +77,12 @@ Keine ### Bestückung -Keine - | Reference | Beschreibung | | -------------- | ---------------------------------------------------------- | -| D5 | JLCPCB plugin, Rotation um 90° | -| U12 | JLCPCB plugin, Rotation um 180° | +| D5 | JLCPCB plugin, Rotation um 90° | +| U12 | JLCPCB plugin, Rotation um 180° | +| R16 | 10R -> 560R (Vorwiderstand blaueLED D4) | +| R72 | 1K -> 3K3 (Vorwiderstand Phototransistor) | ### Funktion / Software diff --git a/software/test_2024-07-23/Makefile b/software/test_2024-07-23/Makefile index 93bc697..2749913 100644 --- a/software/test_2024-07-23/Makefile +++ b/software/test_2024-07-23/Makefile @@ -4,13 +4,13 @@ $(shell mkdir -p build >/dev/null) $(shell mkdir -p sim >/dev/null) NAME="test_2024-07-23_nano-644" -SRC= $(wildcard src/*.c src/*.cpp) +SRC= $(wildcard src/*.c src/*.cpp src/*/*.cpp) OBJ = $(SRC:src/%.c=build/%.o) OBJ_SIM = $(SRC:src/%.c=sim/%.o) DEVICE=atmega644p -CC= avr-gcc +CC= avr-g++ CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -c LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 diff --git a/software/test_2024-07-23/src/main.c b/software/test_2024-07-23/src/main.c deleted file mode 100644 index a737afa..0000000 --- a/software/test_2024-07-23/src/main.c +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include -#include -#include - -int uart_putchar(char c, FILE *stream) { - if (c == '\n') { - uart_putchar('\r', stream); - } - if (stream == stdout) { - loop_until_bit_is_set(UCSR0A, UDRE0); - UDR0 = c; - } else if (stream == stderr) { - loop_until_bit_is_set(UCSR1A, UDRE1); - UDR1 = c; - } - return 0; -} - -static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); -static FILE mystderr = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); - -int main () { - - DDRC = 0x1C; - PORTC = 0x3C; - - UCSR0A = (1 << U2X0); - UCSR0B = (1 << RXCIE0) | (1 << RXEN0) | (1 <= 1000) { -// PORTC ^= (1 << PC4); -// timer = 0; -// } -// } - diff --git a/software/test_2024-07-23/src/main.cpp b/software/test_2024-07-23/src/main.cpp new file mode 100644 index 0000000..68bc39f --- /dev/null +++ b/software/test_2024-07-23/src/main.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include + +#include "main.hpp" +#include "units/led.hpp" +#include "units/switch.hpp" +#include "units/rgb.hpp" +#include "units/seg7.hpp" + +extern "C" { + void __cxa_pure_virtual () { + } + + int uart_putchar(char c, FILE *stream) { + if (c == '\n') { + uart_putchar('\r', stream); + } + if (stream == stdout) { + loop_until_bit_is_set(UCSR0A, UDRE0); + UDR0 = c; + } else if (stream == stderr) { + loop_until_bit_is_set(UCSR1A, UDRE1); + UDR1 = c; + } + return 0; + } + + static FILE mystdout = { 0, 0, _FDEV_SETUP_WRITE , 0, 0, uart_putchar, NULL, 0 } ; + static FILE mystderr = { 0, 0, _FDEV_SETUP_WRITE , 0, 0, uart_putchar, NULL, 0 } ; + + static volatile uint32_t timer1ms = 0; + static volatile int keyUart0 = EOF; +} + +void setTimer (uint32_t ms) { + ATOMIC_BLOCK(ATOMIC_FORCEON) { + timer1ms = ms; + } +} + +int wait (uint32_t ms) { + setTimer(ms); + do { + ATOMIC_BLOCK(ATOMIC_FORCEON) { + ms = timer1ms; + } + } while (ms > 0 && keyUart0 == EOF); + return keyUart0; +} + + +int main () { + + // Nano-644 LEDs (Green, Orange, Red) + DDRC |= (1 << DDC4) | (1 << DDC3) | (1 << DDC2); + PORTC &= ~((1 << PORT4) | (1 << PORT3) | (1 << PORT2)); + + // Nano-644 push button SW2 + DDRC &= ~(1 << DDC5); + PORTC |= (1 << PORT5); // enable internal pullup resistor + + // UART0 interface on Nano-644 + UCSR0A = (1 << U2X0); + UCSR0B = (1 << RXCIE0) | (1 << RXEN0) | (1 <getName()); + printf("Press >ESC< to skip unit, any other key to start\n"); + wait(0xffffffff); + if (keyUart0 == 27) { + keyUart0 = EOF; + continue; + } + keyUart0 = EOF; + + for (uint8_t subtest = 0; subtest < 0xff; subtest++) { + printf("\n%4d: ", subtest); + if (pu->run(subtest) < 0) { + break; + } + if (keyUart0 == 27) { + keyUart0 = EOF; + break; + } + keyUart0 = EOF; + } + pu->cleanup(); + } + + printf("\n\nTest finished. \n"); + return 0; +} + +ISR (USART0_RX_vect) { + uint8_t b = UDR0; + keyUart0 = b; +} + +ISR (TIMER1_COMPA_vect) { + if (timer1ms > 0) { + timer1ms--; + } +} + diff --git a/software/test_2024-07-23/src/main.hpp b/software/test_2024-07-23/src/main.hpp new file mode 100644 index 0000000..b7a0735 --- /dev/null +++ b/software/test_2024-07-23/src/main.hpp @@ -0,0 +1,19 @@ +#ifndef MAIN_HPP +#define MAIN_HPP + +#include + +#define ENTER '\r' +#define CTRLC '\003' + +extern int wait (uint32_t ms); +extern int waitOnKey (char key); + +class TestUnit { + public: + virtual int8_t run (uint8_t subtest) = 0; + virtual void cleanup () = 0; + virtual const char *getName () = 0; +}; + +#endif \ No newline at end of file diff --git a/software/test_2024-07-23/src/units/led.cpp b/software/test_2024-07-23/src/units/led.cpp new file mode 100644 index 0000000..0f4b91b --- /dev/null +++ b/software/test_2024-07-23/src/units/led.cpp @@ -0,0 +1,32 @@ +#include "led.hpp" +#include +#include +#include + +#include "../main.hpp" + +void Led::cleanup () { + DDRD &= ~((1 << DDD7) | (1 << DDD6) | (1 << DDD5) | (1 << DDD4)); + PORTD &= ~((1 << PORTD7) | (1 << PORTD6) | (1 << PORTD5) | (1 << PORTD4)); +} + +int8_t Led::run (uint8_t subtest) { + if (subtest == 0) { + DDRD |= (1 << DDD7) | (1 << DDD6) | (1 << DDD5) | (1 << DDD4); + PORTD &= ~((1 << PORTD7) | (1 << PORTD6) | (1 << PORTD5) | (1 << PORTD4)); + printf("init"); + + } else if (subtest <= 16) { + subtest = (subtest - 1) % 4; + PORTD &= ~((1 << PORTD7) | (1 << PORTD6) | (1 << PORTD5) | (1 << PORTD4)); + PORTD |= (1 << (subtest + 4)); + printf("Test LED PD%d", subtest + 4); + + } else { + printf("end"); + return -1; + } + wait(500); + return 0; +} + diff --git a/software/test_2024-07-23/src/units/led.hpp b/software/test_2024-07-23/src/units/led.hpp new file mode 100644 index 0000000..a76983b --- /dev/null +++ b/software/test_2024-07-23/src/units/led.hpp @@ -0,0 +1,15 @@ +#ifndef LED_HPP +#define LED_HPP + +#include +#include "../main.hpp" + +class Led : public TestUnit { + public: + Led () {}; + virtual void cleanup (); + virtual int8_t run (uint8_t subtest); + virtual const char *getName () { return "Led"; } +}; + +#endif \ No newline at end of file diff --git a/software/test_2024-07-23/src/units/rgb.cpp b/software/test_2024-07-23/src/units/rgb.cpp new file mode 100644 index 0000000..200bffd --- /dev/null +++ b/software/test_2024-07-23/src/units/rgb.cpp @@ -0,0 +1,60 @@ +#include +#include + +#include "rgb.hpp" +#include "../main.hpp" + +void Rgb::cleanup () { + PORTB &= ~((1 << PORTB2) | (1 << PORTB1) | (1 << PORTB0)); + DDRB &= ~((1 << DDB2) | (1 << DDB1) | (1 << DDB0)); +} + +int8_t Rgb::run (uint8_t subtest) { + switch (subtest) { + case 0: { + DDRB |= (1 << DDB2) | (1 << DDB1) | (1 << DDB0); + PORTB |= (1 << PORTB2) | (1 << PORTB1) | (1 << PORTB0); // all OFF + printf("init"); + return 0; + } + + case 1: { + PORTB &= ~(1 << PORTB0); // ON + printf("Red"); + wait(2000); + return 0; + } + + case 2: { + PORTB |= (1 << PORTB0); + PORTB &= ~(1 << PORTB1); // ON + printf("Green"); + wait(2000); + return 0; + } + + case 3: { + PORTB |= (1 << PORTB1); + PORTB &= ~(1 << PORTB2); // ON + printf("Blue"); + wait(2000); + return 0; + } + + case 4: { + PORTB &= ~((1 << PORTB2) | (1 << PORTB1) | (1 << PORTB0)); + printf("All"); + wait(2000); + return 0; + } + + case 5: { + printf("end"); + break; + } + } + + return -1; +} + + diff --git a/software/test_2024-07-23/src/units/rgb.hpp b/software/test_2024-07-23/src/units/rgb.hpp new file mode 100644 index 0000000..2fa8a72 --- /dev/null +++ b/software/test_2024-07-23/src/units/rgb.hpp @@ -0,0 +1,15 @@ +#ifndef RGB_HPP +#define RGB_PP + +#include +#include "../main.hpp" + +class Rgb : public TestUnit { + public: + Rgb () {}; + virtual void cleanup (); + virtual int8_t run (uint8_t subtest); + virtual const char *getName () { return "Rgb"; } +}; + +#endif \ No newline at end of file diff --git a/software/test_2024-07-23/src/units/seg7.cpp b/software/test_2024-07-23/src/units/seg7.cpp new file mode 100644 index 0000000..49030c3 --- /dev/null +++ b/software/test_2024-07-23/src/units/seg7.cpp @@ -0,0 +1,93 @@ +#include +#include + +#include "seg7.hpp" +#include "../main.hpp" + +// PA0 Cathode Char 1 +// PA1 Cathode Char 2 +// PA2 Cathode Char 3 +// PA3 Cathode Char 4 + +// PB0 Anode Segment A +// PB1 Anode Segment B +// PB2 Anode Segment C +// PB3 Anode Segment D +// PB4 Anode Segment E +// PB5 Anode Segment F +// PB6 Anode Segment G +// PB7 Anode DP + +// PD5 nOE (Output Enable) for all LEDs +// PD6 Anode L1:2 +// PD7 Anode L3 + +const char *segName[] = { "A", "B", "C", "D", "E", "F", "G", "DP" }; + +void Seg7::cleanup () { + PORTA &= ~((1 < +#include "../main.hpp" + +class Seg7 : public TestUnit { + public: + Seg7 () {}; + virtual void cleanup (); + virtual int8_t run (uint8_t subtest); + virtual const char *getName () { return "Seg7"; } +}; + +#endif \ No newline at end of file diff --git a/software/test_2024-07-23/src/units/switch.cpp b/software/test_2024-07-23/src/units/switch.cpp new file mode 100644 index 0000000..33d483c --- /dev/null +++ b/software/test_2024-07-23/src/units/switch.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +#include "switch.hpp" +#include "../main.hpp" + +void Switch::cleanup () { + PORTA &= ~((1 << PORTA3) | (1 << PORTA2) | (1 << PORTA1) | (1 << PORTA0)); +} + + +int8_t Switch::run (uint8_t subtest) { + if (subtest == 0) { + DDRA &= ~((1 << DDA3) | (1 << DDA2) | (1 << DDA1) | (1 << DDA0)); + // enable internal pullup resistor + PORTA |= (1 << PORTA3) | (1 << PORTA2) | (1 << PORTA1) | (1 << PORTA0); + wait(10); + return 0; + + } else if (subtest <= 17) { + uint8_t bit = (subtest - 1) / 4; + switch ((subtest - 1) % 4) { + case 0: case 2: { + if ((PINA & (1 << bit)) == 0) { + printf("Release SW%d (PA%d) ", bit + 1, bit); + while ((PINA & (1 << bit)) == 0 && wait(0) == EOF) {} + wait(10); + } + return 0; + } + + case 1: { + if ((PINA & (1 << bit)) != 0) { + printf("Press SW%d (PA%d) ", bit + 1, bit); + while ((PINA & (1 << bit)) != 0 && wait(0) == EOF) {} + wait(10); + } + return 0; + } + + case 3: { + printf("end"); + return 0; + } + } + + } + + return -1; +} diff --git a/software/test_2024-07-23/src/units/switch.hpp b/software/test_2024-07-23/src/units/switch.hpp new file mode 100644 index 0000000..8bdcd74 --- /dev/null +++ b/software/test_2024-07-23/src/units/switch.hpp @@ -0,0 +1,15 @@ +#ifndef SWITCH_HPP +#define SWITCH_HPP + +#include +#include "../main.hpp" + +class Switch : public TestUnit { + public: + Switch () {}; + virtual void cleanup (); + virtual int8_t run (uint8_t subtest); + virtual const char *getName () { return "Switch"; } +}; + +#endif \ No newline at end of file