Commit 31ff4652 authored by Martin Vítek's avatar Martin Vítek
Browse files

Add testing template GPIO lib, but it isn't going to be working

parent c2ceb4b3
cmake_minimum_required(VERSION 3.0)
set(AVR_UPLOADTOOL avrdude)
set(AVR_PROGRAMMER usbasp)
set(AVR_PROGRAMMER atmelice_pdi)
set(AVR_UPLOADTOOL_PORT usb)
set(AVR_MCU atxmega16d4)
set(AVR_H_FUSE 0xC8)
set(AVR_L_FUSE 0x1F)
#set(CMAKE_BUILD_TYPE RelWithDebInfo)
set(CMAKE_BUILD_TYPE Release)
set(MCU_SPEED "14745600UL")
set(MCU_SPEED "2000000UL")
set(WITH_MCU OFF)
set(WITH_MCU OFF CACHE BOOL "Add the mCU type to the target file name." FORCE)
......@@ -35,6 +35,7 @@ set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wl,--gc-sections -Wl,--relax -Os -mrela
set(SOURCE_FILES
main.cpp
gpio.h
)
add_avr_executable(safe-soldering-station ${SOURCE_FILES})
#pragma once
#include <avr/io.h>
#include <stdint.h>
/*
* If this will produce lot of instructions, it's possible to pass address of first port register - PORTA
* and registers are next 23 addresses in memory
*/
enum modes
{
INVERTED,
TOTEM_POLE,
BUS_KEEPER,
TOTEM_PULL_UP,
TOTEM_PULL_DOWN,
WIRED_OR,
WIRED_AND,
WIRED_OR_PULL_DOWN,
WIRED_AND_PULL_UP
};
enum dirs
{
INPUT,
OUTPUT
};
template<PORT_struct *port, uint8_t pin_bm>
class gpio
{
public:
gpio(bool mode = TOTEM_POLE, bool dir = OUTPUT, bool inv = false)
{
port->DIRSET = pin_bm;
port->OUTCLR = pin_bm;
//port->PIN1CTRL
}
gpio()
{
}
void on()
{
port->OUTSET = pin_bm;
}
void off()
{
port->OUTCLR = pin_bm;
}
void toggle()
{
port->OUTTGL = pin_bm;
}
};
/*
template <PORT_t *port, uint8_t pin_mask>
void on()
{
port->OUTSET = pin_mask;
};
*/
\ No newline at end of file
#include <avr/io.h>
#include <util/delay.h>
#include "gpio.h"
int main()
{
PORTD.DIRSET = (1<<PIN0_bm);
gpio<PORTD, PIN0_bm> led();
//gpio<&PORTD, PIN1_bm> lcd();
//on<&PORTD, PIN0_bm>();
for(;;)
{
PORTD.OUTSET = (1<<PIN0_bm);
//led.toggle();
_delay_ms(250);
PORTD.OUTCLR = (1<<PIN0_bm);
//led.toggle();
_delay_ms(250);
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment