Commit 60b5bdbd authored by Daniel Kampert's avatar Daniel Kampert 👷

Remove old projects

parent 83f4a7bd
/*
* USB_Controller.h
*
* Copyright (C) Daniel Kampert, 2018
* Website: www.kampis-elektroecke.de
* File info: USB-Controller for XMega MCUs.
GNU GENERAL PUBLIC LICENSE:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Errors and commissions should be reported to [email protected]
*/
/** @file Arch/XMega/USB/USB_Controller.h
* @brief USB-Controller for AVR8 MCUs.
*
* This file contains the prototypes and definitions for the XMega USB driver.
*
* @author Daniel Kampert
* @bug No known bugs.
*/
#ifndef USB_CONTROLLER_H_
#define USB_CONTROLLER_H_
#endif /* USB_CONTROLLER_H_ */
\ No newline at end of file
/*
* ConsoleService.h
*
* Copyright (C) Daniel Kampert, 2018
* Website: www.kampis-elektroecke.de
* File info: USART Console service for AVR microcontroller.
GNU GENERAL PUBLIC LICENSE:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Errors and commissions should be reported to [email protected]
*/
/** @file Services/ConsoleService/ConsoleService.h
* @brief USART Console service for AVR microcontroller.
*
* This contains the prototypes and definitions for the AVR USART Console.
*
* @author Daniel Kampert
* @bug No known bugs
*/
#ifndef CONSOLESERVICE_H_
#define CONSOLESERVICE_H_
#include "Common/Common.h"
#include <stdio.h>
#if(MCU_ARCH == MCU_ARCH_XMEGA)
#include "Arch/XMega/USART/USART.h"
#else
#error "Architecture not supported for console service!"
#endif
#if(!defined(CONSOLE_STDIO))
#error "'CONSOLE_STDIO' missing for console service!"
#endif
/** @brief Initialize the console service.
*/
void ConsoleService_Init(void);
#endif /* CONSOLESERVICE_H_ */
\ No newline at end of file
/*
* USB.c
*
* Created: 11.05.2017 21:28:03
* Author: Kampi
* Website: www.kampis-elektroecke.de
* File info: Driver for XMega USB
GNU GENERAL PUBLIC LICENSE:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Errors and commissions should be reported to [email protected]
*/
#include "XMega/USB/UDD.h"
#include "XMega/USB/USB.h"
#include "XMega/ClockManagment/SysClock.h"
struct USB_Data_t
{
uint32_t fifo[USB_ENDPOINTS + 1];
USB_EP_t EP[2 * (USB_ENDPOINTS + 1)];
uint16_t frame_number;
};
static volatile struct USB_Data_t USB_Data;
void USB_Init(USB_ClockSource_t USBClock)
{
USB_PowerEnable();
if(USBClock == USB_SOURCE_PLL)
{
//PLL_Config_t USBPLL_Config;
}
else if(USBClock == USB_SOURCE_RC32)
{
DFLL_Disable(&DFLLRC32M);
// Set the calibrated 32 MHz oscillator as clock source for the USB
SysClock_ConfigUSBClock(USB_SOURCE_RC32, SYSCLOCK_USB_PRESCALER_1);
DFLL_Enable(&DFLLRC32M);
}
USB_SetSpeed(USB_SPEED_HIGH);
// Calibrate the USB interface
USB_Calibrate();
// Configure USB interface
USB_SetMaxEndpoints(USB_ENDPOINTS);
USB_Enable();
USB_StoreFrameNumber(TRUE);
}
void USB_Calibrate(void)
{
NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
USB.CAL0 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL0));
NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
USB.CAL1 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL1));
}
void USB_Reset(void)
{
USB_EnableFIFO();
USB_EnableInterrupts(INT_LVL_LO);
USB_Attach();
}
void UDD_Init(void)
{
USB_Init(USB_SOURCE_RC32);
USB.EPPTR = (uint16_t)USB_Data.EP;
USB_Reset();
}
ISR(USB_BUSEVENT_vect)
{
if(USB.INTFLAGSACLR & USB_SOFIF_bm)
{
USB.INTFLAGSACLR = USB_SOFIF_bm;
}
if(USB_INTFLAGSASET & USB_RSTIF_bm)
{
}
if (USB_INTFLAGSASET & USB_SUSPENDIF_bm)
{
USB_INTFLAGSACLR = USB_SUSPENDIF_bm;
}
if (USB_INTFLAGSASET & USB_RESUMEIF_bm)
{
USB_INTFLAGSACLR = USB_RESUMEIF_bm;
}
}
ISR(USB_TRNCOMPL_vect)
{
static uint8_t TT = 0;
}
\ No newline at end of file
/*
* ConsoleService.c
*
* Created: 11.05.2017 21:28:03
* Author: Daniel Kampert
* Website: www.kampis-elektroecke.de
* File info: USART Console service for AVR microcontroller.
GNU GENERAL PUBLIC LICENSE:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Errors and commissions should be reported to [email protected]
*/
/** @file Common/Services/ConsoleService/ConsoleService.c
* @brief USART Console service for AVR microcontroller.
*
* This file contains the implementation for the AVR USART console.
*
* @author Daniel Kampert
*/
#include "Services/ConsoleService/ConsoleService.h"
/** @brief USART interface definition for the console service.
* NOTE: The values are chosen for a clock speed of 2 MHz or 32 MHz.
*/
static USART_Config_t __Config_USART = {
.Device = &CONCAT(CONSOLE_STDIO),
.DeviceMode = USART_MODE_ASYNCH,
.Direction = USART_DIRECTION_BOTH,
.Baudrate = 115200,
.Parity = USART_PARITY_NONE,
.Stop = USART_STOP_1,
.Size = USART_SIZE_8,
.BSCALE = -7,
.EnableDoubleSpeed = FALSE,
};
static int USART_Put(char c, FILE* stream)
{
USART_SendChar(__Config_USART.Device, c);
return 0;
}
static int USART_Get(FILE* stream)
{
return USART_GetChar(__Config_USART.Device);
}
static FILE USART_stdio = FDEV_SETUP_STREAM(USART_Put, USART_Get, _FDEV_SETUP_RW);
void ConsoleService_Init(void)
{
USART_Init(&__Config_USART);
stdout = &USART_stdio;
stdin = &USART_stdio;
}
\ No newline at end of file
/*
* printf.c
*
* Created: 11.05.2017 21:28:03
* Author: Daniel Kampert
* Website: www.kampis-elektroecke.de
* File info: printf implementation for AVR microcontroller.
GNU GENERAL PUBLIC LICENSE:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Errors and commissions should be reported to [email protected]
*/
/** @file Common/Services/ConsoleService/printf.c
* @brief printf implementation for AVR microcontroller.
*
* @author Daniel Kampert
*/
#include "Services/ConsoleService/ConsoleService.h"
/** @brief Print a character string.
* @param String Pointer to character string
* @return Number of bytes
*/
static uint8_t __prints(const char* String)
{
int ByteCounter = 0x00;
while(*String != '\0')
{
putchar(*String++);
ByteCounter++;
}
return ByteCounter;
}
/** @brief Print a integer.
* @param Integer Integer value
* @param Base Value base
* @return Number of bytes
*/
static uint8_t __printi(const int Integer, const int Base)
{
char* pBuffer;
int Integer_Temp = Integer;
// Reserve a transmit buffer. Size depends on the type of 'Number' + array end
char Buffer[sizeof(Integer) + 2] = {0x00};
// Set the end of a char array
Buffer[sizeof(Buffer) - 1] = '\0';
// Pointer to the transmit buffer. Set the pointer to the last element before the
// array end, because the transformation starts with the ones
pBuffer = &Buffer[sizeof(Buffer) - 2];
do
{
*--pBuffer = Representation[Integer_Temp % Base];
Integer_Temp /= Base;
}while(Integer_Temp != 0);
return __prints(pBuffer);
}
/** @brief Print a floating point value.
* @param Float Float value
* @param Length Length of value string
* @param Decimal Decimal places
* @return Number of bytes
*/
static uint8_t __printf(const double Float, const int Length, const int Decimal)
{
int ByteCounter = 0x00;
return ByteCounter;
}
int printf(const char* __fmt, ...)
{
int ByteCounter = 0x00;
va_list argp;
va_start(argp, __fmt);
// Loop through the message string
while(*__fmt != '\0')
{
if(*__fmt == '%')
{
// Skip '%'
__fmt++;
// Convert the value
if(*__fmt == 'd')
{
int d = va_arg(argp, int);
ByteCounter += __printi(d, 10);
}
else if(*__fmt == 'c')
{
int c = va_arg(argp, int);
putchar(c);
ByteCounter++;
}
else if(*__fmt == 's')
{
char* s = va_arg(argp, char*);
ByteCounter += __prints(s);
}
else if(*__fmt == 'x')
{
int d = va_arg(argp, int);
ByteCounter += __printi(d, 16);
}
else if(*__fmt == 'f')
{
double d = va_arg(argp, double);
ByteCounter += __printf(d, 0, 0);
}
}
else
{
putchar(*__fmt);
ByteCounter++;
}
__fmt++;
}
va_end(argp);
return ByteCounter;
}
\ No newline at end of file
Markdown is supported
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