xcd0 / sss

1 stars 0 forks source link

MatrixKeyboardの入出力ピン設定 #4

Closed xcd0 closed 3 months ago

xcd0 commented 3 months ago

AddMatrixKeyboardで https://github.com/sago35/tinygo-keyboard/blob/066aa2b85a5328ec588497ea14d9894261f43cf4/kbmatrix.go#L27-L32

    for c := range colPins {
        colPins[c].Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
    }
    for r := range rowPins {
        rowPins[r].Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
    }

で設定しているのに https://github.com/sago35/tinygo-keyboard/blob/066aa2b85a5328ec588497ea14d9894261f43cf4/kbmatrix.go#L74-L86

func (d *MatrixKeyboard) Get() []State {
    for c := range d.Col {
        for r := range d.Row {
            //d.State[r*len(d.Col)+c] = d.Row[r].Get()
            current := false
            if !d.options.InvertDiode {
                d.Col[c].Configure(machine.PinConfig{Mode: machine.PinOutput})
                d.Col[c].High()
                current = d.Row[r].Get()
            } else {
                d.Row[r].Configure(machine.PinConfig{Mode: machine.PinOutput})
                d.Row[r].High()
                current = d.Col[c].Get()
            }

のようにキースキャン1回ごとに出力ピンを設定している

入出力を切り替える必要があるDuplexや改良二乗マトリクスでは必要だと思われるが、 一方方向にしかスキャンしない一般のキーマトリクスでは不要に思われる。

AddMatrixKeyboardで

    if !d.options.InvertDiode { // COL2ROW
        for c := range colPins {
            colPins[c].Configure(machine.PinConfig{Mode: machine.PinOutput})
        }
        for r := range rowPins {
            rowPins[r].Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
        }
    } else { // ROW2COL
        for c := range colPins {
            colPins[c].Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
        }
        for r := range rowPins {
            rowPins[r].Configure(machine.PinConfig{Mode: machine.PinOutput})
        }
    }

のように設定してはダメだろうか。

xcd0 commented 3 months ago

何か問題があるのかもしれない

xcd0 commented 3 months ago

やってみたらVppが半分以下?になった 何か効果がある模様