Changeset b3f36d2 in mainline


Ignore:
Timestamp:
2011-09-26T09:55:27Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c7325dd6
Parents:
b1926d0
Message:

sb16: Implement volume get/set. Make master the first volume item.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/mixer.c

    rb1926d0 rb3f36d2  
    5353
    5454static const volume_item_t volume_ct1345[] = {
     55        { 0x22, 2, "Master", 8, 1, true },
    5556        { 0x04, 2, "Voice", 8, 1, true },
    5657        { 0x0a, 1, "Mic", 4, 1, true },
    57         { 0x22, 2, "Master", 8, 1, true },
    5858        { 0x26, 2, "MIDI", 8, 1, true },
    5959        { 0x28, 2, "CD", 8, 1, true },
     
    143143/*----------------------------------------------------------------------------*/
    144144int mixer_set_volume_level(sb16_regs_t *regs, mixer_type_t type,
    145     unsigned item, unsigned channel, unsigned level)
     145    unsigned index, unsigned channel, unsigned level)
    146146{
    147         return ENOTSUP;
     147        if (type == SB_MIXER_UNKNOWN || type == SB_MIXER_NONE)
     148                return ENOTSUP;
     149        if (index >= volume_table[type].count)
     150                return ENOENT;
     151        if (level >= volume_table[type].table[index].volume_levels)
     152                return ENOTSUP;
     153        if (channel >= volume_table[type].table[index].channels)
     154                return ENOENT;
     155
     156        const volume_item_t item = volume_table[type].table[index];
     157        const uint8_t address = item.address + (item.same_reg ? 0 : channel);
     158        pio_write_8(&regs->mixer_address, address);
     159        if (!item.same_reg) {
     160                const uint8_t value = level << item.shift;
     161                pio_write_8(&regs->mixer_data, value);
     162        } else {
     163                /* Nasty stuff */
     164                uint8_t value = pio_read_8(&regs->mixer_data);
     165                /* Remove value that is to be replaced register format is L:R*/
     166                value &= (channel ? 0xf0 : 0x0f);
     167                /* Add the new value */
     168                value |= (level << item.shift) << (channel ? 0 : 4);
     169                pio_write_8(&regs->mixer_data, value);
     170        }
     171        return EOK;
    148172}
    149173/*----------------------------------------------------------------------------*/
    150174unsigned mixer_get_volume_level(sb16_regs_t *regs, mixer_type_t type,
    151     unsigned item, unsigned channel)
     175    unsigned index, unsigned channel)
    152176{
     177        if (type == SB_MIXER_UNKNOWN
     178            || type == SB_MIXER_NONE
     179            || (index >= volume_table[type].count)
     180            || (channel >= volume_table[type].table[index].channels))
     181                return 0;
     182
     183        const volume_item_t item = volume_table[type].table[index];
     184        const uint8_t address = item.address + (item.same_reg ? 0 : channel);
     185        pio_write_8(&regs->mixer_address, address);
     186        if (!item.same_reg) {
     187                return pio_read_8(&regs->mixer_data) >> item.shift;
     188        } else {
     189                const uint8_t value =
     190                    pio_read_8(&regs->mixer_data) >> (channel ? 0 : 4);
     191                return value >> item.shift;
     192        }
    153193        return 0;
    154194}
Note: See TracChangeset for help on using the changeset viewer.