~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/hwdef-mateminco-mt35-mini.h

  • Committer: Selene ToyKeeper
  • Date: 2023-11-02 17:05:02 UTC
  • mfrom: (483.12.159 multi-channel)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20231102170502-sinkm18qjxlorsxa
merged multi-channel branch with a major refactor and half a year of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef HWDEF_MT35_MINI_H
2
 
#define HWDEF_MT35_MINI_H
 
1
// Mateminco MT35-Mini / Astrolux FT03
 
2
// Copyright (C) 2022-2023 (original author TBD), Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
 
4
#pragma once
3
5
 
4
 
/* Mateminco MT35-Mini / Astrolux FT03
 
6
/*
5
7
 *           ----
6
8
 *   Reset -|1  8|- VCC
7
9
 * eswitch -|2  7|- Aux LED
10
12
 *           ----
11
13
 */
12
14
 
13
 
#define PWM_CHANNELS 2
14
 
 
 
15
#define ATTINY 85
 
16
#include <avr/io.h>
 
17
 
 
18
#define HWDEF_C_FILE hwdef-emisar-d4.c
 
19
 
 
20
// channel modes
 
21
// * 0. FET+7135 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 2  // 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   // little FET ramp
 
40
#define PWM2_DATATYPE uint8_t   // big FET ramp
 
41
 
 
42
#define PWM_TOP_INIT  255    // highest value used in top half of ramp
 
43
 
 
44
// 1x7135 channel
 
45
#define CH1_PIN  PB4        // pin 3, 1x7135 PWM
 
46
#define CH1_PWM  OCR1B      // OCR1B is the output compare register for PB4
 
47
 
 
48
// DD FET channel
 
49
#define CH2_PIN  PB0        // pin 5, FET PWM
 
50
#define CH2_PWM  OCR0A      // OCR0A is the output compare register for PB0
 
51
 
 
52
// lighted button
 
53
#define AUXLED_PIN   PB2    // pin 7
 
54
 
 
55
// e-switch
15
56
#ifndef SWITCH_PIN
16
57
#define SWITCH_PIN   PB3    // pin 2
17
58
#define SWITCH_PCINT PCINT3 // pin 2 pin change interrupt
18
59
#endif
19
60
 
20
 
#ifndef PWM1_PIN
21
 
#define PWM1_PIN PB4        // pin 3, 1x7135 PWM
22
 
#define PWM1_LVL OCR1B      // OCR1B is the output compare register for PB0
23
 
#endif
24
 
 
25
 
#ifndef PWM2_PIN
26
 
#define PWM2_PIN PB0        // pin 5, FET PWM
27
 
#define PWM2_LVL OCR0A      // OCR0A is the output compare register for PB4
28
 
#endif
29
 
 
30
61
#define ADC_PRSCL   0x07    // clk/128
31
62
 
32
63
// average drop across diode on this hardware
34
65
#define VOLTAGE_FUDGE_FACTOR 7  // add 0.35V
35
66
#endif
36
67
 
37
 
// lighted button
38
 
#ifndef AUXLED_PIN
39
 
#define AUXLED_PIN   PB2    // pin 7
40
 
#endif
41
 
 
42
68
#define FAST 0xA3           // fast PWM both channels
43
69
#define PHASE 0xA1          // phase-correct PWM both channels
44
70
 
 
71
 
 
72
inline void hwdef_setup() {
 
73
    // configure PWM channels
 
74
    DDRB = (1 << CH1_PIN)
 
75
         | (1 << CH2_PIN);
 
76
 
 
77
    // configure PWM channels
 
78
    TCCR0B = 0x01; // pre-scaler for timer (1 => 1, 2 => 8, 3 => 64...)
 
79
    TCCR0A = PHASE;
 
80
 
 
81
    // Second PWM counter is ... weird
 
82
    TCCR1 = _BV (CS10);
 
83
    GTCCR = _BV (COM1B1) | _BV (PWM1B);
 
84
    OCR1C = PWM_TOP_INIT;  // Set ceiling value to maximum
 
85
 
 
86
    // configure e-switch
 
87
    PORTB = (1 << SWITCH_PIN);  // e-switch is the only input
 
88
    PCMSK = (1 << SWITCH_PIN);  // pin change interrupt uses this pin
 
89
}
 
90
 
 
91
 
45
92
#define LAYOUT_DEFINED
46
93
 
47
 
#endif