2 * Copyright © 2017 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
16 #include <ao_as1107.h>
18 static uint8_t as1107_configured;
19 static uint8_t as1107_mutex;
22 ao_as1107_start(void) {
23 ao_spi_get_bit(AO_AS1107_CS_PORT, AO_AS1107_CS_PIN, AO_AS1107_CS, AO_AS1107_SPI_INDEX, AO_AS1107_SPI_SPEED);
27 ao_as1107_stop(void) {
28 ao_spi_put_bit(AO_AS1107_CS_PORT, AO_AS1107_CS_PIN, AO_AS1107_CS, AO_AS1107_SPI_INDEX);
32 _ao_as1107_cmd(uint8_t addr, uint8_t value)
34 uint8_t packet[2] = { addr, value };
37 ao_spi_send(packet, 2, AO_AS1107_SPI_INDEX);
42 _ao_as1107_setup(void)
44 if (!as1107_configured) {
45 as1107_configured = 1;
46 _ao_as1107_cmd(AO_AS1107_SHUTDOWN, AO_AS1107_SHUTDOWN_SHUTDOWN_RESET);
47 _ao_as1107_cmd(AO_AS1107_SHUTDOWN, AO_AS1107_SHUTDOWN_SHUTDOWN_NOP);
48 _ao_as1107_cmd(AO_AS1107_DECODE_MODE, AO_AS1107_DECODE);
49 _ao_as1107_cmd(AO_AS1107_SCAN_LIMIT, AO_AS1107_NUM_DIGITS - 1);
50 _ao_as1107_cmd(AO_AS1107_INTENSITY, 0x0f);
51 _ao_as1107_cmd(AO_AS1107_FEATURE,
52 (0 << AO_AS1107_FEATURE_CLK_EN) |
53 (0 << AO_AS1107_FEATURE_REG_RES) |
54 (1 << AO_AS1107_FEATURE_DECODE_SEL) |
55 (1 << AO_AS1107_FEATURE_SPI_EN) |
56 (0 << AO_AS1107_FEATURE_BLINK_EN) |
57 (0 << AO_AS1107_FEATURE_BLINK_FREQ) |
58 (0 << AO_AS1107_FEATURE_SYNC) |
59 (0 << AO_AS1107_FEATURE_BLINK_START));
60 _ao_as1107_cmd(AO_AS1107_SHUTDOWN, AO_AS1107_SHUTDOWN_NORMAL_NOP);
65 ao_as1107_write(uint8_t start, uint8_t count, uint8_t *values)
68 ao_mutex_get(&as1107_mutex);
70 for (i = 0; i < count; i++)
72 _ao_as1107_cmd(AO_AS1107_DIGIT(start + i),
75 ao_mutex_put(&as1107_mutex);
79 ao_as1107_write_8(uint8_t start, uint8_t value)
83 values[0] = (value >> 4);
84 values[1] = value & 0xf;
85 ao_as1107_write(start, 2, values);
89 ao_as1107_write_16(uint8_t start, uint16_t value)
93 values[0] = (value >> 12);
94 values[1] = (value >> 8) & 0xf;
95 values[2] = (value >> 4) & 0xf;
96 values[3] = (value) & 0xf;
97 ao_as1107_write(start, 4, values);
103 as1107_configured = 0;
104 ao_spi_init_cs(AO_AS1107_CS_PORT, (1 << AO_AS1107_CS_PIN));