-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmds.c
126 lines (104 loc) · 2.35 KB
/
cmds.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright (C) 2017 Urja Rannikko <[email protected]>
*
* 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 2 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.
*/
#include "main.h"
#include "uart.h"
#include "console.h"
#include "lib.h"
#include "ciface.h"
#include "appdb.h"
#include "spihw.h"
#include "adc.h"
CIFACE_APP(vspi_cmd, "VSPI")
{
luint2outdual(measure_vspi());
}
CIFACE_APP(vcc_cmd, "VCC")
{
luint2outdual(measure_vcc());
}
CIFACE_APP(spitest_cmd, "SPILOOP")
{
spi_enable();
spi_hw_on();
luint2outdual(spi_txrx(0xA5));
luint2outdual(spi_txrx(0x5A));
luint2outdual(spi_txrx(0xDB));
}
static void send_hdrval(PGM_P hdr, uint32_t val)
{
sendstr_P(hdr);
u32outdec(val);
}
static void send_pindv(PGM_P hdr, uint8_t mask)
{
send_hdrval(hdr, (PIND & mask) ? 1 : 0 );
}
CIFACE_APP(miso_cmd, "MISO")
{
send_pindv(PSTR("MISO:"), _BV(MISO));
}
CIFACE_APP(spistat_cmd, "SPISTAT")
{
send_hdrval(PSTR("VSPI: "), measure_vspi() );
send_pindv(PSTR("\r\nMISO: "), _BV(MISO));
send_pindv(PSTR("\r\nWP: "), _BV(SPI_WP));
send_pindv(PSTR("\r\nHOLD: "), _BV(SPI_HOLD));
send_pindv(PSTR("\r\n!SPI_EN: "), _BV(SPI_EN));
send_pindv(PSTR("\r\n!CS: "), _BV(SS));
send_pindv(PSTR("\r\nSCK: "), _BV(SCK));
send_pindv(PSTR("\r\nMOSI: "), _BV(MOSI));
}
static void spi_override(uint8_t set, uint8_t clear)
{
spi_enable();
spi_hw_off();
SPI_PORT = (SPI_PORT & ~clear) | set;
spistat_cmd();
}
CIFACE_APP(cs0_cmd, "CS0")
{
spi_override(0, _BV(SS));
}
CIFACE_APP(cs1_cmd, "CS1")
{
spi_override( _BV(SS), 0);
}
CIFACE_APP(sck0_cmd, "SCK0")
{
spi_override(0, _BV(SCK));
}
CIFACE_APP(sck1_cmd, "SCK1")
{
spi_override(_BV(SCK), 0);
}
CIFACE_APP(mosi0_cmd, "MOSI0")
{
spi_override(0, _BV(MOSI));
}
CIFACE_APP(mosi1_cmd, "MOSI1")
{
spi_override(_BV(MOSI), 0);
}
CIFACE_APP(listen_cmd, "LISTEN")
{
}
CIFACE_APP(spioff_cmd, "SPIOFF")
{
spi_disable();
}
CIFACE_APP(f_cpu_cmd, "FREQ")
{
if (CLKPR) sendstr_P(PSTR("8 Mhz (CLKPR set)"));
else sendstr_P(PSTR("16 Mhz (No div)"));
}