Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0x007E committed Jul 28, 2021
0 parents commit 8220b97
Show file tree
Hide file tree
Showing 112 changed files with 232,179 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build Lamp Application

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
# Path to the solution file relative to the root of the project.
SOLUTION_FILE_PATH: lamp\Lamp.sln
BUILD_CONFIGURATION: Release

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Install .NET Core SDK
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: '5.0.302'

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2

- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{env.SOLUTION_FILE_PATH}}

- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
67 changes: 67 additions & 0 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Release Lamp Application

on:
push:
tags-ignore:
- '**-firmware'
env:
# Path to the solution file relative to the root of the project.
SOLUTION_DIRECTORY: lamp
SOLUTION_FILE_PATH: lamp\Lamp.sln
BUILD_CONFIGURATION: Release
OUTPUT_DIRECTORY: output

jobs:
build:
runs-on: windows-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install .NET Core SDK
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: '5.0.302'

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2

- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{env.SOLUTION_FILE_PATH}}

- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
run: |
msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:BaseOutputPath=${{env.GITHUB_WORKSPACE}}\${{env.OUTPUT_DIRECTORY}}\ ${{env.SOLUTION_FILE_PATH}}
- name: Pack
run: |
mkdir ${{env.GITHUB_WORKSPACE}}\${{env.OUTPUT_DIRECTORY}}\${{env.SOLUTION_DIRECTORY}}
Copy-Item -Path ${{env.GITHUB_WORKSPACE}}\${{env.OUTPUT_DIRECTORY}}\Release\net5.0-windows\* -Destination ${{env.GITHUB_WORKSPACE}}\${{env.OUTPUT_DIRECTORY}}\${{env.SOLUTION_DIRECTORY}}\ -Recurse
mkdir ${{env.GITHUB_WORKSPACE}}\${{env.OUTPUT_DIRECTORY}}\${{env.SOLUTION_DIRECTORY}}\Update
Copy-Item -Path ${{env.GITHUB_WORKSPACE}}\${{env.OUTPUT_DIRECTORY}}\Release\net5.0\* -Destination ${{env.GITHUB_WORKSPACE}}\${{env.OUTPUT_DIRECTORY}}\${{env.SOLUTION_DIRECTORY}}\Update\ -Recurse
Get-ChildItem ${{env.GITHUB_WORKSPACE}}\${{env.OUTPUT_DIRECTORY}}\${{env.SOLUTION_DIRECTORY}} | Compress-Archive -DestinationPath ${{env.GITHUB_WORKSPACE}}\Lamp.zip
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{env.GITHUB_WORKSPACE}}\Lamp.zip
asset_name: Lamp.zip
asset_content_type: application/zip

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!.travis.yml
!.gitignore
60 changes: 60 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Travis CI build pipeline
# --------------------------------------------
language: c
os: linux

addons:
apt:
packages:
- binutils-avr
- avr-libc
- gcc-avr
- git

install:
- |
git --version
avr-gcc --version
make --version
before_script:
- set -e
- |
avr-gcc -g -x c -O1 -mmcu=atmega8a -std=gnu99 -c ./firmware/main.c
avr-gcc -g -x c -O1 -mmcu=atmega8a -std=gnu99 -c ./firmware/adc/adc.c
avr-gcc -g -x c -O1 -mmcu=atmega8a -std=gnu99 -c ./firmware/led/led.c
avr-gcc -g -x c -O1 -mmcu=atmega8a -std=gnu99 -c ./firmware/prom/prom.c
avr-gcc -g -x c -O1 -mmcu=atmega8a -std=gnu99 -c ./firmware/sensor/sensor.c
avr-gcc -g -x c -O1 -mmcu=atmega8a -std=gnu99 -c ./firmware/spi/spi.c
avr-gcc -g -x c -O1 -mmcu=atmega8a -std=gnu99 -c ./firmware/system/system.c
avr-gcc -g -x c -O1 -mmcu=atmega8a -std=gnu99 -c ./firmware/uart/uart.c
script:
- |
avr-gcc -g -mmcu=atmega8a -o firmware.elf main.o adc.o led.o prom.o sensor.o spi.o system.o uart.o
avr-objcopy -j .text -j .data -O ihex firmware.elf firmware.hex
avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex firmware.elf firmware.eep
before_deploy:
- |
if [ -n $TRAVIS_TAG ] && [[ $TRAVIS_TAG =~ ^v[0-9].[0-9]-[(F|f)]irmware$ ]]; then
travis_terminate 0
fi
- set -e
- git config --local user.name "0x007E"
- |
zip -r ./Firmware.zip ./firmware.hex ./firmware.eep
tar cfvz ./Firmware.tar.gz ./firmware.hex ./firmware.eep
- export TRAVIS_TAG="${TRAVIS_TAG}-Firmware"

deploy:
provider: releases
overwrite: true
api_key: $GITHUB_TOKEN
file_glob: true
file:
- "./Firmware.zip"
- "./Firmware.tar.gz"
skip_cleanup: true
on:
tags: true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
View this project on [CADLAB.io](https://cadlab.io/project/23814/main/files).

22 changes: 22 additions & 0 deletions firmware/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Ignore Atmel Studio temporary files and build results
# https://www.microchip.com/mplab/avr-support/atmel-studio-7

# Atmel Studio is powered by an older version of Visual Studio,
# so most of the project and solution files are the same as VS files,
# only prefixed by an `at`.

#Build Directories
[Dd]ebug/
[Rr]elease/

#Build Results
*.o
*.d
*.eep
*.elf
*.hex
*.map
*.srec

#User Specific Files
*.atsuo
200 changes: 200 additions & 0 deletions firmware/adc/adc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/* -----------------------------------------
* G.Raf^engineering
* www.sunriax.at
* -----------------------------------------
* Platform: Megacard
* Hardware: ATmega16
* -----------------------------------------
* Version: 1.0 Release
* Author: G.Raf
* Description:
* Function file for adc library
* -----------------------------------------
*/

#include "adc.h"

// +---------------------------------------------------------------+
// | ADC initialization |
// +---------------------------------------------------------------+
void adc_init(void)
{
// Setup ADC parameters
ADMUX = (((0x03 & ADC_REF)<<6) | ((0x01 & ADC_DATA_SHIFT)<<5));

// Setup ADC prescaler
// F_ADC = F_CPU / ADC_PRESCALER
ADCSRA = ((0x07 & ADC_PRESCALER));

// Setup ADC permanent transformation and trigger source
#if ADC_MODE == 0x01
ADCSRA |= (1<<ADEN) | (1<<ADSC) | (1<<ADATE);

SFIOR &= ~(0xE0);
SFIOR |= ((0x07 & ADC_TRIGGER_SOURCE)<<5);
#endif

// Check if ADC interrupt handler is active
#ifdef ADC_ADIE
ADCSRA |= (1<<ADIE); // Enable ADC interrupt
sei(); // Enable global interrupt
#endif
}

// +---------------------------------------------------------------+
// | ADC disable function |
// +---------------------------------------------------------------+
void adc_disable(void)
{
ADCSRA &= ~(1<<ADEN); // Disable ADC
}

// +---------------------------------------------------------------+
// | ADC mode selection |
// +---------------------------------------------------------------+
// | Parameter: mode -> 0x00 = Singled ended input |
// | ADC0 - ADC7 |
// | 0x01 = Differential input | Gain |
// | ADC0 - ADC0 (CH0) | 10x |
// | ADC1 - ADC0 (CH1) | 10x |
// | ADC0 - ADC0 (CH0) | 200x |
// | ADC1 - ADC0 (CH1) | 200x |
// | ADC2 - ADC2 (CH2) | 10x |
// | ADC3 - ADC2 (CH3) | 10x |
// | ADC2 - ADC2 (CH2) | 200x |
// | ADC3 - ADC2 (CH3) | 200x |
// | 0x02 = Differential input | Gain |
// | ADC0 - ADC1 (CH0) | 1x |
// | ADC1 - ADC1 (CH1) | 1x |
// | ADC2 - ADC1 (CH2) | 1x |
// | ADC3 - ADC1 (CH3) | 1x |
// | ADC4 - ADC1 (CH4) | 1x |
// | ADC5 - ADC1 (CH5) | 1x |
// | ADC6 - ADC1 (CH6) | 1x |
// | ADC7 - ADC1 (CH7) | 1x |
// | 0x03 = Differential input | Gain |
// | ADC0 - ADC2 (CH0) | 1x |
// | ADC1 - ADC2 (CH1) | 1x |
// | ADC2 - ADC2 (CH2) | 1x |
// | ADC3 - ADC2 (CH3) | 1x |
// | ADC4 - ADC2 (CH4) | 1x |
// | ADC5 - ADC2 (CH5) | 1x |
// | --- Special --- |
// | 1.22V Ref (CH6) |
// | 0V Ref (CH7) |
// +---------------------------------------------------------------+
void adc_mode(ADC_Mode mode)
{
ADMUX = (ADMUX & 0xE7) | ((0x03 & mode)<<3); // Setup ADC Mode
}

// +---------------------------------------------------------------+
// | ADC channel selection |
// +---------------------------------------------------------------+
// | Parameter: channel -> 0x00 = CH0 (Standard after init) |
// | 0x01 = CH1 |
// | 0x02 = CH2 |
// | 0x03 = CH3 |
// | 0x04 = CH4 |
// | 0x05 = CH5 |
// | 0x06 = CH6 |
// | 0x07 = CH7 |
// +---------------------------------------------------------------+
void adc_channel(ADC_Channel channel)
{
ADMUX = (ADMUX & ~(0x07)) | (0x07 & channel); // Select ADC Channel
}

#ifndef ADC_ADIE

// +---------------------------------------------------------------+
// | ADC read value |
// +---------------------------------------------------------------+
// | Return: -> RIGHT shift of ADC data register |
// +-------------------------------+-------------------------------+
// | ADCH | ADCL |
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
// | - | - | - | - | - | - | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
// | |
// | -> LEFT shift of ADC data register |
// +-------------------------------+-------------------------------+
// | ADCH | ADCL |
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
// | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | - | - | - | - | - | - |
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
unsigned int adc_read(void)
{
#ifdef ADC_NOISE_REDUCTION
// Enter ADC noise reduction mode (stop the CPU)
MCUCR &= ~((1<<SM2) | (1<<SM1));
MCUCR |= (1<<SM0);
#endif

#if ADC_MODE == 0x01

// Wait until ADC interrupt flag is zero
while(!(ADCSRA & (1<<ADIF)))
asm volatile("NOP");

unsigned char ADC_LOW = ADCL; // Save ADC LOW value to variable
unsigned char ADC_HIGH = ADCH; // Save ADC HIGH value to variable

ADCSRA |= (1<<ADIF); // Reset ADC interrupt flag

// Return ADC high + low value
return ((ADC_HIGH<<8) | ADC_LOW);

#else

// Start single conversion
ADCSRA |= (1<<ADEN) | (1<<ADSC);

// Wait until conversion is in progress
while(ADCSRA & (1<<ADSC))
asm volatile("NOP");

unsigned char ADC_LOW = ADCL; // Save ADC LOW value to variable
unsigned char ADC_HIGH = ADCH; // Save ADC HIGH value to variable

// Return ADC high + low value
return ((ADC_HIGH<<8) | ADC_LOW);

#endif

#ifdef ADC_NOISE_REDUCTION
// Exit ADC noise reduction mode (start the CPU)
MCUCR &= ~((1<<SM2) | (1<<SM1)) | (1<<SM0));
#endif

}

// +---------------------------------------------------------------+
// | ADC read average from values |
// +---------------------------------------------------------------+
// | Parameter: size -> quantity of conversions |
// | |
// | Return: 0x???? -> Arithmetic average |
// | of converted data |
// +---------------------------------------------------------------+
unsigned int adc_average(unsigned char size)
{
unsigned long average = 0; // average buffer

// Read and add ADC values
for(unsigned char i=0; i < size; i++)
{
#if ADC_DATA_SHIFT == 1
average += (adc_read()>>6);
#else
average += adc_read();
#endif
}

average /= size; // Build average

// Return average as unsigned int
return (unsigned int)(average);
}

#endif
Loading

0 comments on commit 8220b97

Please sign in to comment.