some stuff
This commit is contained in:
37
labW6barnestr/Inc/delay.h
Normal file
37
labW6barnestr/Inc/delay.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* delay.h
|
||||
*
|
||||
* Created on: Dec 10, 2021
|
||||
* Author: Trevor Barnes
|
||||
*/
|
||||
|
||||
//include guards
|
||||
#ifndef DELAY_H_
|
||||
#define DELAY_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define STK_CTRL (volatile uint32_t*) 0xE000E010
|
||||
#define STK_LOAD (volatile uint32_t*) 0xE000E014
|
||||
#define STK_VAL (volatile uint32_t*) 0xE000E018
|
||||
|
||||
#define EN 1
|
||||
#define TICKINT (1<<1)
|
||||
#define CLKSOURCE (1<<2)
|
||||
#define COUNTFLAG (1<<16)
|
||||
|
||||
/*
|
||||
* delay_1ms
|
||||
* Busy wait for n ms
|
||||
*
|
||||
* For n iterations
|
||||
* load number of cycles for 1 ms
|
||||
* set one to enable and clock source
|
||||
*
|
||||
* wait for countflag to be set
|
||||
*/
|
||||
void delay_1ms(uint32_t n);
|
||||
|
||||
|
||||
|
||||
#endif /* DELAY_H_ */
|
||||
101
labW6barnestr/Inc/led.h
Normal file
101
labW6barnestr/Inc/led.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* led.h
|
||||
*
|
||||
* Created on: Dec 10, 2021
|
||||
* Author: Trevor Barnes
|
||||
*/
|
||||
|
||||
#ifndef LED_H_
|
||||
#define LED_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define RCC_AHB1ENR (volatile uint32_t*) 0x40023830
|
||||
#define GPIOBEN 1
|
||||
#define GPIOB_MODER (volatile uint32_t*) 0x40020400
|
||||
#define GPIOB_PUPDR (volatile uint32_t*) 0x4002040C
|
||||
#define GPIOB_IDR (volatile uint32_t*) 0x40020410
|
||||
#define GPIOB_ODR (volatile uint32_t*) 0x40020414
|
||||
#define GPIOB_BSRR (volatile uint32_t*) 0x40020418
|
||||
|
||||
#define ALL_LEDS (0b11110111111<<5)
|
||||
|
||||
/*
|
||||
* led_init()
|
||||
* This function should:
|
||||
* 1. Enable the GPIOB in RCC_AHB1ENR
|
||||
* 2. Turn on to set LED0 - LED9 to output mode ("01")
|
||||
*/
|
||||
void led_init();
|
||||
|
||||
/*
|
||||
* led_allOn()
|
||||
* 1. Turn on all leds (hint use ODR or BSRR)
|
||||
* Note you should not effect other pins on PortB
|
||||
*/
|
||||
void led_allOn();
|
||||
|
||||
/*
|
||||
* led_allOff()
|
||||
* 1. Turn off all leds (hint use ODR or BSRR)
|
||||
* Note you should not effect other pins on PortB
|
||||
*/
|
||||
void led_allOff();
|
||||
|
||||
/*
|
||||
* led_on()
|
||||
* Args: 0-9 to turn on specific led
|
||||
* print error message is arg is out of range
|
||||
*/
|
||||
void led_on(uint8_t ledIndex);
|
||||
|
||||
/*
|
||||
* led_off()
|
||||
* Args: 0-9 to turn off specific led
|
||||
* print error message is arg is out of range
|
||||
*/
|
||||
void led_off(uint8_t ledIndex);
|
||||
|
||||
|
||||
/*
|
||||
* led_scan()
|
||||
* Scan the light across and back at the current speed
|
||||
*/
|
||||
void led_scan();
|
||||
|
||||
/*
|
||||
* led_flash()
|
||||
* flash all of the lights 10 times at the current speed
|
||||
*/
|
||||
void led_flash();
|
||||
|
||||
/*
|
||||
* led_setSpeed (uint8_t speed)
|
||||
* arg: speed (0 slow - 9 fast)
|
||||
* Args out of range should print error to console
|
||||
*/
|
||||
void led_setSpeed(uint8_t speed);
|
||||
|
||||
/*
|
||||
* led_incSpeed()
|
||||
* increases the speed by one
|
||||
* if maxed out leaves the speed at the max value
|
||||
*/
|
||||
void led_incSpeed();
|
||||
|
||||
/*
|
||||
* led_decSpeed()
|
||||
* decreases the speed by one
|
||||
* if at zero should stay at zero
|
||||
*/
|
||||
void led_decSpeed();
|
||||
|
||||
/*
|
||||
* getCurrentSpeed
|
||||
* returns the current speed
|
||||
*/
|
||||
uint8_t getCurrentSpeed();
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
35
labW6barnestr/Inc/memory.h
Normal file
35
labW6barnestr/Inc/memory.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file memory.h
|
||||
* @author Trevor Barnes
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-19
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
//include guards
|
||||
#ifndef MEMORY_H_
|
||||
#define MEMORY_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "uart_driver.h"
|
||||
|
||||
void initMemConsole();
|
||||
|
||||
/**
|
||||
* Reads and prints the memory value at address provided: "addr"
|
||||
*/
|
||||
void readMem(uint32_t addr);
|
||||
/**
|
||||
* Writes the provided "data" value as an unsigned 32-bit word at the provided address: "addr"
|
||||
*/
|
||||
void writeMem(uint32_t addr, uint32_t data);
|
||||
/**
|
||||
* Prints out formatted, hexadecimal memory values in "byte-sized" chunks starting at the provided
|
||||
* memory address: "addr". The length of the memory dump is provided by "length".
|
||||
*/
|
||||
void dumpMem(uint32_t addr, int length);
|
||||
|
||||
#endif /* MEMORY_H_ */
|
||||
171
labW6barnestr/Inc/piezoSpeaker.h
Normal file
171
labW6barnestr/Inc/piezoSpeaker.h
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* @file piezoSpeaker.h
|
||||
* @author Trevor Barnes
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-19
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PIEZOSPEAKER_H_
|
||||
#define PIEZOSPEAKER_H_
|
||||
|
||||
// RCC
|
||||
#define RCC_AHB1ENR (volatile uint32_t*) 0x40023830
|
||||
#define RCC_APB1ENR (volatile uint32_t*) 0x40023840
|
||||
|
||||
// GPIOB
|
||||
#define GPIOB_MODER (volatile uint32_t*) 0x40020400
|
||||
#define GPIOBEN 1
|
||||
#define GPIOB_AFRL (volatile uint32_t*) 0x40020420
|
||||
#define AFRL_TIM3_CH1_EN 17
|
||||
|
||||
// Timer 3
|
||||
#define TIM3_EN 1
|
||||
#define TIM3_CCMR1 (volatile uint32_t*) 0x40000418
|
||||
#define OC1PE 3
|
||||
#define OC1M_PWM2 0b1110000
|
||||
#define TIM3_CCER (volatile uint32_t*) 0x40000420
|
||||
#define CCER_CC1E 1
|
||||
#define TIM3_EGR (volatile uint32_t*) 0x40000414
|
||||
#define EGR_UG 1
|
||||
#define TIM3_PSC (volatile uint32_t*) 0x40000428
|
||||
#define TIM3_ARR (volatile uint32_t*) 0x4000042C
|
||||
#define TIM3_CCR1 (volatile uint32_t*) 0x40000434
|
||||
#define TIM3_CR1 (volatile uint32_t*) 0x40000400
|
||||
#define CR_ARPE_EN 7
|
||||
#define CR_CEN 1
|
||||
|
||||
#define PB4_AF_V 0b10
|
||||
#define PB4_AF_P 9
|
||||
|
||||
#define mil 1000000
|
||||
|
||||
typedef struct{
|
||||
double noteFrequency;
|
||||
double noteDuration;
|
||||
} Note;
|
||||
|
||||
void piezo_init();
|
||||
|
||||
int play_note(Note noteToPlay);
|
||||
// void play_note(double playFrequency, double playDuration);
|
||||
|
||||
void play_song(Note *song);
|
||||
|
||||
// Note Frequency Symbols
|
||||
// Rest technically = 0
|
||||
#define r 0
|
||||
#define C0 16.35
|
||||
#define Db0 17.32
|
||||
#define D0 18.35
|
||||
#define Eb0 19.45
|
||||
#define E0 20.60
|
||||
#define F0 21.83
|
||||
#define Gb0 23.12
|
||||
#define G0 24.50
|
||||
#define Ab0 25.96
|
||||
#define A0 27.50
|
||||
#define Bb0 29.14
|
||||
#define B0 30.87
|
||||
#define C1 32.70
|
||||
#define Db1 34.65
|
||||
#define D1 36.71
|
||||
#define Eb1 38.89
|
||||
#define E1 41.20
|
||||
#define F1 43.65
|
||||
#define Gb1 46.25
|
||||
#define G1 49.00
|
||||
#define Ab1 51.91
|
||||
#define A1 55.00
|
||||
#define Bb1 58.27
|
||||
#define B1 61.74
|
||||
#define C2 65.41
|
||||
#define Db2 69.30
|
||||
#define D2 73.42
|
||||
#define Eb2 77.78
|
||||
#define E2 82.41
|
||||
#define F2 87.31
|
||||
#define Gb2 92.50
|
||||
#define G2 98.00
|
||||
#define Ab2 103.83
|
||||
#define A2 110.00
|
||||
#define Bb2 116.54
|
||||
#define B2 123.47
|
||||
#define C3 130.81
|
||||
#define Db3 138.59
|
||||
#define D3 146.83
|
||||
#define Eb3 155.56
|
||||
#define E3 164.81
|
||||
#define F3 174.61
|
||||
#define Gb3 185.00
|
||||
#define G3 196.00
|
||||
#define Ab3 207.65
|
||||
#define A3 220.00
|
||||
#define Bb3 233.08
|
||||
#define B3 246.94
|
||||
#define C4 261.63
|
||||
#define Db4 277.18
|
||||
#define D4 293.66
|
||||
#define Eb4 311.13
|
||||
#define E4 329.63
|
||||
#define F4 349.23
|
||||
#define Gb4 369.99
|
||||
#define G4 392.00
|
||||
#define Ab4 415.30
|
||||
#define A4 440.00
|
||||
#define Bb4 466.16
|
||||
#define B4 493.88
|
||||
#define C5 523.25
|
||||
#define Db5 554.37
|
||||
#define D5 587.33
|
||||
#define Eb5 622.25
|
||||
#define E5 659.26
|
||||
#define F5 698.46
|
||||
#define Gb5 739.99
|
||||
#define G5 783.99
|
||||
#define Ab5 830.61
|
||||
#define A5 880.00
|
||||
#define Bb5 932.33
|
||||
#define B5 987.77
|
||||
#define C6 1046.50
|
||||
#define Db6 1108.73
|
||||
#define D6 1174.66
|
||||
#define Eb6 1244.51
|
||||
#define E6 1318.51
|
||||
#define F6 1396.91
|
||||
#define Gb6 1479.98
|
||||
#define G6 1567.98
|
||||
#define Ab6 1661.22
|
||||
#define A6 1760.00
|
||||
#define Bb6 1864.66
|
||||
#define B6 1975.53
|
||||
#define C7 2093.00
|
||||
#define Db7 2217.46
|
||||
#define D7 2349.32
|
||||
#define Eb7 2489.02
|
||||
#define E7 2637.02
|
||||
#define F7 2793.83
|
||||
#define Gb7 2959.96
|
||||
#define G7 3135.96
|
||||
#define Ab7 3322.44
|
||||
#define A7 3520.01
|
||||
#define Bb7 3729.31
|
||||
#define B7 3951.07
|
||||
#define C8 4186.01
|
||||
#define Db8 4434.92
|
||||
#define D8 4698.64
|
||||
#define Eb8 4978.03
|
||||
// Ending "termination" value indicating end of a song
|
||||
#define T 5000.00
|
||||
// Tempo value set at 120 beats per min
|
||||
#define BPM 120
|
||||
#define H 2*Q
|
||||
#define Q 60000/BPM
|
||||
#define E Q/2
|
||||
#define S Q/4
|
||||
#define W 4*Q
|
||||
|
||||
#endif
|
||||
49
labW6barnestr/Inc/uart_driver.h
Normal file
49
labW6barnestr/Inc/uart_driver.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* uart_driver.h
|
||||
*
|
||||
* Created on: Nov 8, 2016
|
||||
* Author: barnekow
|
||||
*/
|
||||
|
||||
#ifndef UART_DRIVER_H_
|
||||
#define UART_DRIVER_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
// RCC registers
|
||||
#define RCC_APB1ENR (volatile uint32_t*) 0x40023840
|
||||
#define RCC_AHB1ENR (volatile uint32_t*) 0x40023830
|
||||
|
||||
#define GPIOAEN 0 // GPIOA Enable is bit 0 in RCC_APB1LPENR
|
||||
#define USART2EN 17 // USART2 enable is bit 17 in RCC_AHB1LPENR
|
||||
|
||||
// GPIOA registers
|
||||
#define GPIOA_MODER (volatile uint32_t*) 0x40020000
|
||||
#define GPIOA_AFRL (volatile uint32_t*) 0x40020020
|
||||
#define USART_SR (volatile uint32_t*) 0x40004400
|
||||
#define USART_DR (volatile uint32_t*) 0x40004404
|
||||
#define USART_BRR (volatile uint32_t*) 0x40004408
|
||||
#define USART_CR1 (volatile uint32_t*) 0x4000440c
|
||||
#define USART_CR2 (volatile uint32_t*) 0x40004410
|
||||
#define USART_CR3 (volatile uint32_t*) 0x40004414
|
||||
|
||||
// CR1 bits
|
||||
#define UE 13 //UART enable
|
||||
#define TE 3 // Transmitter enable
|
||||
#define RE 2 // Receiver enable
|
||||
|
||||
// Status register bits
|
||||
#define TXE 7 // Transmit register empty
|
||||
#define RXNE 5 // Receive register is not empty..char received
|
||||
|
||||
// Function prototypes
|
||||
extern void init_usart2(uint32_t baud, uint32_t sysclk);
|
||||
extern char usart2_getch();
|
||||
extern void usart2_putch(char c);
|
||||
|
||||
// syscalls overrides
|
||||
int _read(int file, char *ptr, int len);
|
||||
int _write(int file, char *ptr, int len);
|
||||
|
||||
|
||||
#endif /* UART_DRIVER_H_ */
|
||||
Reference in New Issue
Block a user