~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/hwdef-fw3a.h

  • Committer: Selene ToyKeeper
  • Date: 2023-11-04 15:09:10 UTC
  • mfrom: (483.1.175 anduril2)
  • Revision ID: bzr@toykeeper.net-20231104150910-ddd3afw4nhfvof2l
merged anduril2 branch -> fsm, with *years* of changes
(this also means this code is now Anduril 2 instead of Anduril 1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef HWDEF_FW3A_H
2
 
#define HWDEF_FW3A_H
 
1
// BLF/TLF FW3A driver layout
 
2
// Copyright (C) 2018-2023 Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
 
4
#pragma once
3
5
 
4
 
/* BLF/TLF FW3A driver layout
 
6
/*
5
7
 *           ----
6
8
 *   Reset -|1  8|- VCC
7
9
 * eswitch -|2  7|- optic nerve
10
12
 *           ----
11
13
 */
12
14
 
13
 
#define PWM_CHANNELS 3
14
 
 
 
15
#define ATTINY 85
 
16
#include <avr/io.h>
 
17
 
 
18
#define HWDEF_C_FILE hwdef-fw3a.c
 
19
 
 
20
// channel modes
 
21
// * 0. FET+7+1 stacked
 
22
#define NUM_CHANNEL_MODES   1
 
23
enum CHANNEL_MODES {
 
24
    CM_MAIN = 0,
 
25
};
 
26
 
 
27
#define DEFAULT_CHANNEL_MODE  CM_MAIN
 
28
 
 
29
// right-most bit first, modes are in fedcba9876543210 order
 
30
#define CHANNEL_MODES_ENABLED 0b00000001
 
31
 
 
32
 
 
33
#define PWM_CHANNELS 3  // old, remove this
 
34
 
 
35
#define PWM_BITS      8       // attiny85 only supports up to 8 bits
 
36
#define PWM_GET       PWM_GET8
 
37
#define PWM_DATATYPE  uint8_t
 
38
#define PWM_DATATYPE2 uint16_t
 
39
#define PWM1_DATATYPE uint8_t   // 1x7135 ramp
 
40
#define PWM2_DATATYPE uint8_t   // 7x7135 ramp
 
41
#define PWM3_DATATYPE uint8_t   // DD FET ramp
 
42
 
 
43
#define PWM_TOP_INIT  255    // highest value used in top half of ramp
 
44
 
 
45
// 1x7135 channel
 
46
#define CH1_PIN  PB0        // pin 5, 1x7135 PWM
 
47
#define CH1_PWM  OCR0A      // OCR0A is the output compare register for PB0
 
48
 
 
49
// 7x7135 channel
 
50
#define CH2_PIN  PB1        // pin 6, 7x7135 PWM
 
51
#define CH2_PWM  OCR0B      // OCR0B is the output compare register for PB1
 
52
 
 
53
// DD FET channel
 
54
#define CH3_PIN  PB4        // pin 3, FET PWM
 
55
#define CH3_PWM  OCR1B      // OCR1B is the output compare register for PB4
 
56
 
 
57
// e-switch
15
58
#ifndef SWITCH_PIN
16
59
#define SWITCH_PIN   PB3    // pin 2
17
60
#define SWITCH_PCINT PCINT3 // pin 2 pin change interrupt
18
61
#endif
19
62
 
20
 
#ifndef PWM1_PIN
21
 
#define PWM1_PIN PB0        // pin 5, 1x7135 PWM
22
 
#define PWM1_LVL OCR0A      // OCR0A is the output compare register for PB0
23
 
#endif
24
 
#ifndef PWM2_PIN
25
 
#define PWM2_PIN PB1        // pin 6, 7x7135 PWM
26
 
#define PWM2_LVL OCR0B      // OCR0B is the output compare register for PB1
27
 
#endif
28
 
#ifndef PWM3_PIN
29
 
#define PWM3_PIN PB4        // pin 3, FET PWM
30
 
#define PWM3_LVL OCR1B      // OCR1B is the output compare register for PB4
31
 
#endif
32
 
 
33
63
#ifndef VISION_PIN
34
64
#define VISION_PIN PB2      // pin 7, optic nerve
35
65
//#define ADC_CHANNEL 0x01    // MUX 01 corresponds with PB2
45
75
#define FAST 0xA3           // fast PWM both channels
46
76
#define PHASE 0xA1          // phase-correct PWM both channels
47
77
 
 
78
 
 
79
inline void hwdef_setup() {
 
80
 
 
81
    // configure PWM channels
 
82
    DDRB = (1 << CH1_PIN)
 
83
         | (1 << CH2_PIN)
 
84
         | (1 << CH3_PIN);
 
85
 
 
86
    // configure PWM channels
 
87
    TCCR0B = 0x01; // pre-scaler for timer (1 => 1, 2 => 8, 3 => 64...)
 
88
    TCCR0A = PHASE;
 
89
 
 
90
    // Second PWM counter is ... weird
 
91
    TCCR1 = _BV (CS10);
 
92
    GTCCR = _BV (COM1B1) | _BV (PWM1B);
 
93
    OCR1C = PWM_TOP_INIT;  // Set ceiling value to maximum
 
94
 
 
95
    // configure e-switch
 
96
    PORTB = (1 << SWITCH_PIN);  // e-switch is the only input
 
97
    PCMSK = (1 << SWITCH_PIN);  // pin change interrupt uses this pin
 
98
 
 
99
    // TODO: set up the vision pin
 
100
 
 
101
}
 
102
 
 
103
 
48
104
#define LAYOUT_DEFINED
49
105
 
50
 
#endif