Skip to content

Commit

Permalink
init_rep
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhozic committed May 21, 2021
0 parents commit 007a93b
Show file tree
Hide file tree
Showing 11 changed files with 745 additions and 0 deletions.
13 changes: 13 additions & 0 deletions EEPROM/EEPROM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


#pragma once


class EEPROM_t
{
public:
void pisi(uint8_t podatek, uint16_t naslov);
uint8_t beri (uint16_t naslov);
};

extern EEPROM_t EEPROM;
28 changes: 28 additions & 0 deletions EEPROM/eeprom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#include "avr/io.h"
#include "FreeRTOS.h"
#include "avr/interrupt.h"
#include "libs/EEPROM/EEPROM.h"
#include "common/inc/FreeRTOS_def_decl.h"

void EEPROM_t::pisi(uint8_t podatek, uint16_t naslov){
if (EEPROM_t::beri(naslov) == podatek)
return;
while(EECR & (1<<EEPE)); // Cakaj da se prejsnje branje/pisanje zakljuci
EEAR = naslov; //Izberi index bajta na eepromu
EEDR = podatek; //Podatek na zacasen bajt
EECR |= (1<<EEMPE); //Vklopi interrupt
EECR |= (1<<EEPE); //Pisi
}

uint8_t EEPROM_t::beri (uint16_t naslov){
while(EECR & (1<<EEPE)) delayFREERTOS(1); // Cakaj da se prejsnje branje/pisanje zakljuci
EEAR = naslov; //Izberi index bajta na eepromu
EECR |= (1<<EERE); //Beri
while(EECR & 1<<EERE);
return EEDR; //Vrni vrednost
}
EEPROM_t EEPROM;



50 changes: 50 additions & 0 deletions VHOD/Vhod.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#ifndef VHOD_H
#define VHOD_H

#include <stdint.h>
#include "avr/io.h"

/************************************************************/
/* SETTINGS */

#define FILTER_TIME_MS 50
#define USE_FILTERING 1
/************************************************************/


#if (USE_FILTERING == 1)
#include "castimer.hh"
#endif


class class_VHOD // pin, port, stanje ko ni pritisnjen
{
private:
uint8_t filtered_curr_state : 1;
uint8_t unfiltered_curr_state : 1;
uint8_t prev_state : 1;
uint8_t rising_edge : 1;
uint8_t falling_edge : 1;
uint8_t default_state : 1;

uint8_t pin;
char port;
#if (USE_FILTERING == 1)
class_TIMER filter_timer;
#endif

public:
bool vrednost();
bool risingEdge();
bool fallingEdge();

class_VHOD(uint8_t pin, char port, char default_state);
};

#define readBIT(reg, bit) ( ( (reg >> bit) & 0x1 ) )
#define writeBIT(reg, bit, val) ( (reg = val ? ( reg | (0x1 << bit) ) : ( reg & ~(0x1 << bit))) )

#endif


179 changes: 179 additions & 0 deletions VHOD/vhod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#include "Vhod.hh"


bool class_VHOD::vrednost()
{
switch (port)
{
#ifdef PINA
case 'A':
unfiltered_curr_state = readBIT(PINA, pin);
break;
#endif

#ifdef PINB
case 'B':
unfiltered_curr_state = readBIT(PINB, pin);
break;
#endif

#ifdef PINC
case 'C':
unfiltered_curr_state = readBIT(PINC, pin);
break;
#endif

#ifdef PIND
case 'D':
unfiltered_curr_state = readBIT(PIND, pin);
break;
#endif

#ifdef PINE
case 'E':
unfiltered_curr_state = readBIT(PINE, pin);
break;
#endif

#ifdef PINF
case 'F':
unfiltered_curr_state = readBIT(PINF, pin);
break;
#endif

#ifdef PING
case 'G':
unfiltered_curr_state = readBIT(PING, pin);
break;
#endif

#ifdef PINH
case 'H':
unfiltered_curr_state = readBIT(PINH, pin);
break;
#endif

#ifdef PINI
case 'I':
unfiltered_curr_state = readBIT(PINI, pin);
break;
#endif

#ifdef PINJ
case 'J':
unfiltered_curr_state = readBIT(PINJ, pin);
break;
#endif


#ifdef PINK
case 'K':
unfiltered_curr_state = readBIT(PINK, pin);
break;
#endif

#ifdef PINL
case 'L':
unfiltered_curr_state = readBIT(PINL, pin);
break;
#endif

#ifdef PINM
case 'M':
unfiltered_curr_state = readBIT(PINM, pin);
break;
#endif

default:
break;
}



// END READING OF PIN
/************************/

/* Invert output if unpressed input state is 1 */
if (default_state)
{
unfiltered_curr_state = !unfiltered_curr_state;
}

#if (USE_FILTERING == 1)
/* Filter input with a timer */
if (unfiltered_curr_state != filtered_curr_state
&& filter_timer.vrednost() >= FILTER_TIME_MS)
{
filtered_curr_state = unfiltered_curr_state;
}
else if(unfiltered_curr_state == filtered_curr_state)
{
filter_timer.ponastavi();
}
#else
filtered_curr_state = unfiltered_curr_state;
#endif
/* END OF FILTERING*/

/* Edge detection */
if (prev_state != filtered_curr_state)
{
/* If state has changed and input is high -> rising edge*/
if (filtered_curr_state)
{
rising_edge = 1;
}
else
{
falling_edge = 1;
}
prev_state = filtered_curr_state;
}

/* Clear edges if input state doesn't match */
if (!filtered_curr_state)
{
rising_edge = 0;
}
else if(filtered_curr_state){
falling_edge = 0;
}


return filtered_curr_state;
}

bool class_VHOD::risingEdge()
{
vrednost();
if (rising_edge)
{
rising_edge = 0;
return true;
}
return false;
}

bool class_VHOD::fallingEdge()
{
vrednost();
if (falling_edge)
{
falling_edge = 0;
return true;
}
return false;
}

class_VHOD::class_VHOD(unsigned char pin, char port, char default_state)
{
this->port = port;
this->pin = pin;
this->default_state = default_state;
filtered_curr_state = 0;
unfiltered_curr_state = 0;
rising_edge = 0;
falling_edge = 0;
}


29 changes: 29 additions & 0 deletions castimer/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
27 changes: 27 additions & 0 deletions castimer/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Loading

0 comments on commit 007a93b

Please sign in to comment.