Skip to content

Commit

Permalink
reset && active
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr committed Oct 15, 2021
1 parent bfad3d0 commit 8a90963
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
23 changes: 23 additions & 0 deletions drivers/usb2422.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ static void USB2422_write_block(void) {
}

void USB2422_init() {
#ifdef USB2422_RESET_PIN
setPinOutput(USB2422_RESET_PIN);
#endif
#ifdef USB2422_ACTIVE_PIN
setPinInput(USB2422_ACTIVE_PIN);
#endif

i2c_init(); // IC2 clk must be high at USB2422 reset release time to signal SMB configuration
}

Expand Down Expand Up @@ -365,3 +372,19 @@ void USB2422_configure() {

USB2422_write_block();
}

void USB2422_reset() {
#ifdef USB2422_RESET_PIN
writePinLow(USB2422_RESET_PIN);
wait_us(2);
writePinHigh(USB2422_RESET_PIN);
#endif
}

bool USB2422_active() {
#ifdef USB2422_ACTIVE_PIN
return read_pin(USB2422_ACTIVE_PIN);
#else
return 1;
#endif
}
6 changes: 6 additions & 0 deletions drivers/usb2422.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
#pragma once

#include <stdbool.h>

#ifndef USB2422_ADDRESS
# define USB2422_ADDRESS 0x58
#endif
Expand All @@ -39,3 +41,7 @@
void USB2422_init(void);

void USB2422_configure(void);

void USB2422_reset(void);

bool USB2422_active(void);
1 change: 1 addition & 0 deletions keyboards/massdrop/alt/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define USB2422_DEVICE_VER 0x0101
#define USB2422_MANUFACTURER "Massdrop Inc."
#define USB2422_PRODUCT "Massdrop Hub"
#define USB2422_ACTIVE_PIN A18

/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
#define DEBOUNCE 5
Expand Down
1 change: 1 addition & 0 deletions keyboards/massdrop/ctrl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define USB2422_DEVICE_VER 0x0101
#define USB2422_MANUFACTURER "Massdrop Inc."
#define USB2422_PRODUCT "Massdrop Hub"
#define USB2422_ACTIVE_PIN A18

/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
#define DEBOUNCE 5
Expand Down
4 changes: 1 addition & 3 deletions tmk_core/protocol/arm_atsam/usb/usb_hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ void USB_Hub_init(void) {
pusb->DEVICE.QOSCTRL.bit.DQOS = 2;
pusb->DEVICE.QOSCTRL.bit.CQOS = 2;

pport->Group[USB2422_HUB_ACTIVE_GROUP].PINCFG[USB2422_HUB_ACTIVE_PIN].bit.INEN = 1;

USB2422_init();

sr_exp_data.bit.HUB_CONNECT = 1; // connect signal
Expand Down Expand Up @@ -152,7 +150,7 @@ void USB_configure(void) {
DBGC(DC_USB_CONFIGURE_COMPLETE);
}

uint16_t USB_active(void) { return (PORT->Group[USB2422_HUB_ACTIVE_GROUP].IN.reg & (1 << USB2422_HUB_ACTIVE_PIN)) != 0; }
uint16_t USB_active(void) { return USB2422_active(); }

void USB_set_host_by_voltage(void) {
// UP is upstream device (HOST)
Expand Down
3 changes: 0 additions & 3 deletions tmk_core/protocol/arm_atsam/usb/usb_hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#define REV_USB2422 0x100

#define USB2422_HUB_ACTIVE_GROUP 0 // PA
#define USB2422_HUB_ACTIVE_PIN 18 // 18

#define PORT_DETECT_RETRY_INTERVAL 2000

#define USB_EXTRA_ADC_THRESHOLD 900
Expand Down

0 comments on commit 8a90963

Please sign in to comment.