You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.7 KiB

2 weeks ago
#include "anaout.h"
#define BIT(n) (1u << (n))
2 weeks ago
static void write_port(volatile uint8_t *port, uint8_t mask, uint8_t on)
{
if (on) *port |= mask;
else *port &= (uint8_t)~mask;
}
/* ?? -> (?? ??, ???) ??? */
static volatile uint8_t * const s_port[21] = {
0,
&P6, &P6, &P6, &P6, // 1~4
&P4, &P4, &P4, &P4, // 5~8
&P5, &P5, &P5, // 9~11
&P6, &P6, // 12~13
&P7, &P7, &P7, &P7, &P7, &P7, // 14~19
&P13 // 20
};
2 weeks ago
2 weeks ago
static const uint8_t s_mask[21] = {
0,
(uint8_t)BIT(4), (uint8_t)BIT(5), (uint8_t)BIT(6), (uint8_t)BIT(7), // P64~P67
(uint8_t)BIT(4), (uint8_t)BIT(3), (uint8_t)BIT(2), (uint8_t)BIT(1), // P44,P43,P42,P41
(uint8_t)BIT(0), (uint8_t)BIT(1), (uint8_t)BIT(2), // P50,P51,P52
(uint8_t)BIT(0), (uint8_t)BIT(1), // P60,P61
(uint8_t)BIT(2), (uint8_t)BIT(3), (uint8_t)BIT(5), (uint8_t)BIT(4), (uint8_t)BIT(6), (uint8_t)BIT(7), // P72~P77
(uint8_t)BIT(0) // P130
};
2 weeks ago
2 weeks ago
void ANAOUT_Set(uint8_t ch, uint8_t on)
2 weeks ago
{
2 weeks ago
if (ch < 1 || ch > 20) return;
write_port(s_port[ch], s_mask[ch], on);
2 weeks ago
}
2 weeks ago
void ANAOUT_AllOff(void)
2 weeks ago
{
2 weeks ago
uint8_t ch;
for (ch = 1; ch <= 20; ch++)
{
ANAOUT_Set(ch, 0);
}
2 weeks ago
}
void ANAOUT_Select(uint8_t ch)
2 weeks ago
{
if (ch < 1 || ch > 20) return;
ANAOUT_AllOff();
ANAOUT_Set(ch, 1);
}
2 weeks ago
2 weeks ago
void anaout_pin(uint8_t ch, uint8_t on)
{
if (ch < 1 || ch > 20) return;
2 weeks ago
2 weeks ago
if (on) {
// on=1?? "??" ???? ??(??? 1?? ??)
ANAOUT_Select(ch);
} else {
// off? ?? ??? OFF
ANAOUT_Set(ch, 0);
2 weeks ago
}
}
2 weeks ago
void anaout_all_off(void)
{
ANAOUT_AllOff();
}