This repository has been archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.h
61 lines (49 loc) · 2.42 KB
/
main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
******************************************************************************
* FuncGen - A function generator based on the AD9833, controlled by an STM8
*
* @author Brad Roy
* @version V1.1dev Rotary Encoder support
* @date 04-Dec-2020
*****************************************************************************/
//function declarations
static void CLK_Config(void);
static void SPI_Config(void);
static void GPIO_Config(void);
static void Setup(void);
static long enc_read(void);
/*inline long map(long x, long in_min, long in_max, long out_min, long out_max)
{return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }*/
/*inline int abs(int x)
{return x < 0 ? -x : x; }*/
int putchar(int c);
//int getchar(void);
/* Pin Assignments------------------------------------------------------------*/
//awkward - pin d2 == ADC1 channel3, would be nice to do this with one #define instead of two
#define POTPIN GPIOD, GPIO_PIN_2 //our frequency control potentiometer pin
#define POTCH ADC1_CHANNEL_3 //make sure this corresponds to the pin chosed on previous
/* Pin Assignment for AD9833. Assumes CLK and DAT are using hardware SPI pins */
#define SPISS GPIOC, GPIO_PIN_7 //our slave select pin: defined in AD9833.c
/* Pins Assignment for LCD module, 4-bit mode */
#define LCD_DB7 GPIOC,GPIO_PIN_4 // C4
#define LCD_DB6 GPIOC,GPIO_PIN_3 // C3
#define LCD_DB5 GPIOB,GPIO_PIN_4 // B4
#define LCD_DB4 GPIOB,GPIO_PIN_5 // B5
#define LCD_EN GPIOA,GPIO_PIN_2 // A2
#define LCD_RS GPIOA,GPIO_PIN_1 // A1
#define ENCODER_BTN GPIOD,GPIO_PIN_6 // mode shift button
#define ENCODER_1 GPIOD,GPIO_PIN_3
#define ENCODER_2 GPIOD,GPIO_PIN_4
#define TICK_PIN GPIOD,GPIO_PIN_5 //output our systick frequency on this pin
/*Global Variable declarations*/
//globals for our ISR to use - probably better to set up a struct to represent our encoder....
static volatile unsigned int encoder_btn_event = 0;
static volatile int direction = 0;
//this should be a static within the read_enc() fn, but that crashes SDCC
//due to https://sourceforge.net/p/sdcc/bugs/2741/ and https://sourceforge.net/p/sdcc/bugs/3161/
static unsigned long encoder_accel = 1;
//timer variables, used to track the last time a process has been run
unsigned int encoder_polled = 0; //track encoder inputs, to determine velocity
//strings for our display
char modes[3][9]={"SINE ","TRIANGLE","SQUARE "};
//main.h