Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // reads CDJ-100S buttons
- void Keyboard_Read() {
- HAL_GPIO_WritePin(S1_GPIO_Port, S1_Pin, GPIO_PIN_SET);
- if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << HOLD))) {
- button_flags ^= (1 << HOLD);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Hold_On, 4);
- }
- Display_DataTx(Hold_On, 4);
- }
- }
- else {
- if(button_flags & (1 << HOLD)) {
- button_flags ^= (1 << HOLD);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Hold_Off, 4);
- }
- Display_DataTx(Hold_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << TRACKBACK))) {
- button_flags ^= (1 << TRACKBACK);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(TrackBack_On, 4);
- }
- Display_DataTx(TrackBack_On, 4);
- }
- }
- else {
- if(button_flags & (1 << TRACKBACK)) {
- button_flags ^= (1 << TRACKBACK);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(TrackBack_Off, 4);
- }
- Display_DataTx(TrackBack_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD2_GPIO_Port, KD2_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << PLAY))) {
- button_flags ^= (1 << PLAY);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Play_On, 4);
- }
- Display_DataTx(Play_On, 4);
- }
- }
- else {
- if(button_flags & (1 << PLAY)) {
- button_flags ^= (1 << PLAY);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Play_Off, 4);
- }
- Display_DataTx(Play_Off, 4);
- }
- }
- HAL_GPIO_WritePin(S1_GPIO_Port, S1_Pin, GPIO_PIN_RESET);
- HAL_GPIO_WritePin(S2_GPIO_Port, S2_Pin, GPIO_PIN_SET);
- if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << TIME))) {
- button_flags ^= (1 << TIME);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Time_On, 4);
- }
- Display_DataTx(Time_On, 4);
- }
- }
- else {
- if(button_flags & (1 << TIME)) {
- button_flags ^= (1 << TIME);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Time_Off, 4);
- }
- Display_DataTx(Time_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << TRACKFORWARD))) {
- button_flags ^= (1 << TRACKFORWARD);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(TrackForward_On, 4);
- }
- Display_DataTx(TrackForward_On, 4);
- }
- }
- else {
- if(button_flags & (1 << TRACKFORWARD)) {
- button_flags ^= (1 << TRACKFORWARD);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(TrackForward_Off, 4);
- }
- Display_DataTx(TrackForward_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD2_GPIO_Port, KD2_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << CUE))) {
- button_flags ^= (1 << CUE);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Cue_On, 4);
- }
- Display_DataTx(Cue_On, 4);
- }
- }
- else {
- if(button_flags & (1 << CUE)) {
- button_flags ^= (1 << CUE);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Cue_Off, 4);
- }
- Display_DataTx(Cue_Off, 4);
- }
- }
- HAL_GPIO_WritePin(S2_GPIO_Port, S2_Pin, GPIO_PIN_RESET);
- HAL_GPIO_WritePin(S3_GPIO_Port, S3_Pin, GPIO_PIN_SET);
- if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << EJECT))) {
- button_flags ^= (1 << EJECT);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Eject_On, 4);
- }
- Display_DataTx(Eject_On, 4);
- }
- }
- else {
- if(button_flags & (1 << EJECT)) {
- button_flags ^= (1 << EJECT);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Eject_Off, 4);
- }
- Display_DataTx(Eject_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << JET))) {
- button_flags ^= (1 << JET);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Jet_On, 4);
- }
- Display_DataTx(Jet_On, 4);
- }
- }
- else {
- if(button_flags & (1 << JET)) {
- button_flags ^= (1 << JET);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Jet_Off, 4);
- }
- Display_DataTx(Jet_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD2_GPIO_Port, KD2_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << SCANBACK))) {
- button_flags ^= (1 << SCANBACK);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(ScanBack_On, 4);
- }
- Display_DataTx(ScanBack_On, 4);
- }
- }
- else {
- if(button_flags & (1 << SCANBACK)) {
- button_flags ^= (1 << SCANBACK);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(ScanBack_Off, 4);
- }
- Display_DataTx(ScanBack_Off, 4);
- }
- }
- HAL_GPIO_WritePin(S3_GPIO_Port, S3_Pin, GPIO_PIN_RESET);
- HAL_GPIO_WritePin(S4_GPIO_Port, S4_Pin, GPIO_PIN_SET);
- if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << MASTERTEMPO))) {
- button_flags ^= (1 << MASTERTEMPO);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(MasterTempo_On, 4);
- }
- Display_DataTx(MasterTempo_On, 4);
- }
- }
- else {
- if(button_flags & (1 << MASTERTEMPO)) {
- button_flags ^= (1 << MASTERTEMPO);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(MasterTempo_Off, 4);
- }
- Display_DataTx(MasterTempo_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << ZIP))) {
- button_flags ^= (1 << ZIP);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Zip_On, 4);
- }
- Display_DataTx(Zip_On, 4);
- }
- }
- else {
- if(button_flags & (1 << ZIP)) {
- button_flags ^= (1 << ZIP);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Zip_Off, 4);
- }
- Display_DataTx(Zip_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD2_GPIO_Port, KD2_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << SCANFORWARD))) {
- button_flags ^= (1 << SCANFORWARD);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(ScanForward_On, 4);
- }
- Display_DataTx(ScanForward_On, 4);
- }
- }
- else {
- if(button_flags & (1 << SCANFORWARD)) {
- button_flags ^= (1 << SCANFORWARD);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(ScanForward_Off, 4);
- }
- Display_DataTx(ScanForward_Off, 4);
- }
- }
- HAL_GPIO_WritePin(S4_GPIO_Port, S4_Pin, GPIO_PIN_RESET);
- HAL_GPIO_WritePin(S5_GPIO_Port, S5_Pin, GPIO_PIN_SET);
- if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << JOG))) {
- button_flags ^= (1 << JOG);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Jog_On, 4);
- }
- Display_DataTx(Jog_On, 4);
- }
- }
- else {
- if(button_flags & (1 << JOG)) {
- button_flags ^= (1 << JOG);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Jog_Off, 4);
- }
- Display_DataTx(Jog_Off, 4);
- }
- }
- if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
- if(!(button_flags & (1 << WAH))) {
- button_flags ^= (1 << WAH);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Wah_On, 4);
- }
- Display_DataTx(Wah_On, 4);
- }
- }
- else {
- if(button_flags & (1 << WAH)) {
- button_flags ^= (1 << WAH);
- if(usb_status == CONNECTED) {
- MIDI_DataTx(Wah_Off, 4);
- }
- Display_DataTx(Wah_Off, 4);
- }
- }
- HAL_GPIO_WritePin(S5_GPIO_Port, S5_Pin, GPIO_PIN_RESET);
- }
- / transmit data to STM32F746DISCO board via SPI1
- void Display_DataTx(uint8_t *data, uint16_t length) {
- HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_RESET);
- HAL_SPI_Transmit(&hspi1, data, length, 0x1000);
- HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_SET);
- }
- // receive data from STM32F746DISCO board via SPI1
- void Display_DataRx() {
- uint8_t dummy_data[4] = {0};
- HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_RESET);
- HAL_SPI_TransmitReceive(&hspi1, dummy_data, spi_rx_buffer, 4, 0x1000);
- HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_SET);
- if((spi_rx_buffer[1] & 0xF0) == 0x90) {
- if((spi_rx_buffer[2] & (1 << 0))) {
- HAL_GPIO_WritePin(PLAY_GPIO_Port, PLAY_Pin, GPIO_PIN_SET);
- }
- else {
- HAL_GPIO_WritePin(PLAY_GPIO_Port, PLAY_Pin, GPIO_PIN_RESET);
- }
- if((spi_rx_buffer[2] & (1 << 1))) {
- HAL_GPIO_WritePin(CUE_GPIO_Port, CUE_Pin, GPIO_PIN_SET);
- }
- else {
- HAL_GPIO_WritePin(CUE_GPIO_Port, CUE_Pin, GPIO_PIN_RESET);
- }
- if((spi_rx_buffer[2] & (1 << 2))) {
- HAL_GPIO_WritePin(DISC_GPIO_Port, DISC_Pin, GPIO_PIN_SET);
- }
- else {
- HAL_GPIO_WritePin(DISC_GPIO_Port, DISC_Pin, GPIO_PIN_RESET);
- }
- if((spi_rx_buffer[2] & (1 << 3))) {
- Display_DataTx(Pitch, 4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement