Example #1
0
void settings_init(uint8_t * addr)
{
    uint8_t *src_p, *dst_p;
    uint8_t *ptr;
    uint8_t right, left;
    uint8_t i;

    src_p = addr;
    dst_p = (uint8_t *) & s;
    if ((*src_p) != VERSION) {
        src_p = (uint8_t *) & defaults;
    }
    for (i = 0; i < sizeof(s); i++) {
        *dst_p++ = *src_p++;
    }

    // apply settings to hardware

    ptr = (uint8_t *) & s.v;
    for (i = 1; i < 7; i++) {
        right = *(ptr + (i * 2 - 2));
        left = *(ptr + (i * 2 - 2) + 1);
        if ((left != 0) && (right != 0)) {
            pga_set_volume(i, right, left, 0, 0);
        }
        if (s.mute_flag & (1 << (i - 1))) {
            pga_set_mute_st(i, UNMUTE, 0);
        } else {
            pga_set_mute_st(i, MUTE, 0);
        }
    }

}
Example #2
0
static void i2c_rx_irq(enum sys_message msg)
{
    uint8_t *flash_addr = FLASH_ADDR;

    uint8_t cmd = i2c_rx_buff[0];
    uint8_t arg = i2c_rx_buff[1];
    uint8_t mute_st = i2c_rx_buff[2];
    uint8_t vol_r = i2c_rx_buff[3];
    uint8_t vol_l = i2c_rx_buff[4];

    switch (cmd) {

        case M_CMD_WRITE:
            if (arg == 2) {
                flash_addr = SEGMENT_C;
            } else if (arg == 3) {
                flash_addr = SEGMENT_D;
            } else {
                flash_addr = SEGMENT_B;
            }
            flash_save(flash_addr, (void *)&s, sizeof(s));
            break;

        case M_CMD_READ:
            if (arg == 2) {
                flash_addr = SEGMENT_C;
            } else if (arg == 3) {
                flash_addr = SEGMENT_D;
            } else {
                flash_addr = SEGMENT_B;
            }
            settings_init(flash_addr);
            break;

        case M_CMD_VOL:
            if ((0 < arg) && (arg < 7) && ((mute_st == MUTE) || (mute_st == UNMUTE))) {
                pga_set_volume(arg, vol_r, vol_l, 1, 1);
                if (mute_st != mixer_get_mute_struct(arg)) {
                    if (mute_st == MUTE) {
                        pga_set_mute_st(arg, MUTE, 1);
                    } else { 
                        pga_set_mute_st(arg, UNMUTE, 1);
                    }
                }
            }
            break;

        case M_CMD_MUTE:
            if ((0 < arg) && (arg < 7)) {
                pga_set_mute_st(arg, MUTE, 1);
            }
            break;

        case M_CMD_UNMUTE:
            if ((0 < arg) && (arg < 7)) {
                pga_set_mute_st(arg, UNMUTE, 1);
            }
            break;
    }

    i2c_rx_rdy = 1;
}
Example #3
0
static void uart1_rx_irq(enum sys_message msg)
{
    uint16_t u16;
    uint8_t p;
    uint8_t pga, ch, left = 0, right = 0;
    uint8_t *flash_addr = FLASH_ADDR;
    char *input;
    uint8_t *ptr;
    uint8_t allfine = 0;

    input = (char *)uart1_rx_buf;

    p = input[0];
    if (p > 97) {
        p -= 32;
    }

    if ((p == 63) || (p == M_CMD_HELP)) {       // [h?]
        display_help();
    } else if (p == M_CMD_SHOW) {        // [s]how settings
        show_settings();
        uart1_tx_str("ok\r\n", 4);
    } else if (p == M_CMD_WRITE) {       // [w]rite to flash
        if (str_to_uint16(input, &u16, 1, 1, 1, 3)) {
            if (u16 == 1) {
                flash_addr = SEGMENT_B;
            } else if (u16 == 2) {
                flash_addr = SEGMENT_C;
            } else if (u16 == 3) {
                flash_addr = SEGMENT_D;
            }
            flash_save(flash_addr, (void *)&s, sizeof(s));
            uart1_tx_str("ok\r\n", 4);
        }
    } else if (p == M_CMD_READ) {       // [r]ead from flash
        if (str_to_uint16(input, &u16, 1, 1, 1, 3)) {
            if (u16 == 1) {
                flash_addr = SEGMENT_B;
            } else if (u16 == 2) {
                flash_addr = SEGMENT_C;
            } else if (u16 == 3) {
                flash_addr = SEGMENT_D;
            }
            settings_init(flash_addr);
            uart1_tx_str("ok\r\n", 4);
        }
    } else if (p == M_CMD_MUTE) {       // [m]ute pga
        if (str_to_uint16(input, &u16, 1, 1, 1, 6)) {
            pga = u16;
            pga_set_mute_st(pga, MUTE, 1);
            uart1_tx_str("ok\r\n", 4);
        }
    } else if (p == M_CMD_UNMUTE) {     // [u]nmute pga
        if (str_to_uint16(input, &u16, 1, 1, 1, 6)) {
            pga = u16;
            pga_set_mute_st(pga, UNMUTE, 1);
            uart1_tx_str("ok\r\n", 4);
        }
    } else if (p == M_CMD_VOL) {       // [v]olume set
        if (str_to_uint16(input, &u16, 1, 1, 1, 6)) {
            pga = u16;
            ch = input[2];
            if (str_to_uint16(input, &u16, 3, strlen(input) - 3, 0, 255)) {
                ptr = (uint8_t *) & s.v1_r;
                if (ch == 98) {
                    // 'b' - change both channels
                    right = u16;
                    left = u16;
                    allfine = 1;
                } else if (ch == 114) {
                    // 'r' - only change the right channel
                    right = u16;
                    left = *(ptr + (pga * 2 - 2) + 1);
                    allfine = 1;
                } else if (ch == 108) {
                    // 'l' - only change the left channel
                    right = *(ptr + (pga * 2 - 2));
                    left = u16;
                    allfine = 1;
                }
                if (allfine) {
                    pga_set_volume(pga, right, left, 1, 1);
                    uart1_tx_str("ok\r\n", 4);
                }
            }
        }
    }
    //snprintf(str_temp, TEMP_LEN, "D 0x%x 0x%x 0x%x\r\n", input[0], input[1], input[2]);
    //uart1_tx_str(str_temp, strlen(str_temp));

    uart1_p = 0;
    uart1_rx_enable = 1;
}