コード例 #1
0
ファイル: main.cpp プロジェクト: uriahjb/symphotron
int main( void )
{
    mInit();
    mUSBInit();
    mBusInit();

    // Set up usb interface
    bQueue in_q;
    bQueue out_q;
    usbIface usb( &in_q, &out_q );
    
//    picker_setup();
    stepper_setup();
//    set_timer5 (60000,30000,1200);
    
    setMode( STEP_8TH);
    setSpeedLimits( 65, 500 );
    set_speed(m_speed_min);
    setAccelerationLimit(100); //5000 is good
    
    uint8_t cmd; 
    uint16_t pos = 0;
    while(1)
    {
        usb.readBytes();

        // Handle bytes 
        if (!in_q.isempty() ) {
          mBlueTOGGLE;
          in_q.dequeue(&cmd);
          if ( cmd == 'l' ) {
            pos += 10;
          } else if ( cmd == 'h' ) {
            pos -= 10;
          }
        }
        update(pos);
    }
    return(0);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: uriahjb/symphotron
int main( void )
{
    // Initialize m4 things
    mInit();
    //mBusInit();
    mUSBInit();

    // Set up usb interface
    bQueue in_q;
    bQueue out_q;
    usbIface usb( &in_q, &out_q );
    
    // Initialize midi interface
    midiParser midi( &in_q );
    midiMsg msg;

    mYellowON;
    
    while(1)
    {
      usb.readBytes();
      /*
      mWaitms(500);
      mGreenON;
      usb.printf( "hello world\n" );
      mWaitms(500);
      mGreenOFF;
      */
      if ( midi.hasMsg(&msg) ) {
        mGreenTOGGLE;
        usb.printf("msg: %02x\n", msg.status);
        usb.printf("channel: %02x\n", msg.channel);
        usb.printf("data[0]: %02x\n", msg.data[0]);
        usb.printf("data[1]: %02x\n", msg.data[1]);
      }
      // Write data out 
      usb.writeBytes();
    }
}
コード例 #3
0
ファイル: main.c プロジェクト: vincentwenxuan/smores_document
int main( void )
{
    uint8_t d = 0x34,rxbuf = 0X23;
    mInit();
    // I2C_config();
    SPI_config();
    debug_setup();
    ADC_A_config();
    GPIO_InitTypeDef  GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //M4 DIRECTION
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //M3 DIRECTION
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
    TIMA_config(100, 20,10); // timer1 channel 1 PA8
    TIMB_config(100, 20,10); // timer2 channel 3 PA9
    TIMC_config(100, 20,10); // timer15 channel 1 PB14
    TIMD_config(100, 20,10); // timer2 channel 2 PA1 // first 2 numbers
    //                          // in this function are not doing anything   
    while(1)
    {
        GPIO_ResetBits(GPIOA, GPIO_Pin_0);
        GPIO_ResetBits(GPIOB, GPIO_Pin_15);
        // debug_write_ch(0XAB);
        mBlueTOGGLE;
        mGreenTOGGLE;
        mRedTOGGLE;
        mWaitms(300);
        GPIO_SetBits(GPIOA, GPIO_Pin_0);
        GPIO_SetBits(GPIOB, GPIO_Pin_15);
            /* Test EOC flag */
        while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
    
        /* Get ADC1 converted data */
        ADC1ConvertedValue =ADC_GetConversionValue(ADC1);
        debug_write_u16(ADC1ConvertedValue,10);
        debug_write_line("  ");

        // mWaitms(300);
        // I2C_write_1byte(SLAVE_ADDR2,254,22);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR,254);
        // debug_write_ch(rxbuf);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR1,254);
        // debug_write_ch(rxbuf);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR2,254);
        // debug_write_ch(rxbuf);
    // TIM_SetCompare2 ( TIM2,1);
    // mWaitms(300);
    // TIM_SetCompare2 ( TIM2,0);
    // mWaitms(1000);
        // SPI_SendData8(SPI1, d);
        // while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
        // while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
        // rxbuf =  SPI_ReceiveData8(SPI1);
    }

}
void RsdCpuScriptImpl::invokeInit() {
    if (mInit) {
        mInit();
    }
}
コード例 #5
0
ファイル: main.c プロジェクト: uriahjb/symphotron
int main( void )
{
    mInit();
    mUSBInit();
    //mBusInit();
    
    bQueue in_q;
    bQueue out_q;
    bQueueInit( &in_q );
    bQueueInit( &out_q );
    usbIface usb;
    usbIfaceInit( &usb, &in_q, &out_q );
    
    // Set up midi parser
    midiParser parser;
    midiParserInit( &parser, &in_q );
    midiMsg msg;
    
    picker_setup();
    stepper_setup();
    set_timer5 (60000,30000,1200);
   
    setMode( STEP_HALF );
    setSpeedLimits( 65, 200 );
    set_speed(m_speed_min);
    setAccelerationLimit(200);
    
    int test=0;
    
    //    uint16_t pos[]={0,-180,0,-360,0,-540,0,-720,-900,0};
    //    uint16_t dur[]={1000,1000,1000,1000};
    
    uint16_t pos=0;
    /*
    //set_speed(m_speed_min);
    int i=0;
    update(0);
    //    TIM_Cmd(TIM5, DISABLE);
    accStop();
    setPosition(0);
    */
    int Sflag=0;
    
    
    //strum_delay(1);
    while(1)
    {
        //        test = update(pos);
        //        if(test==1){
        //            if(Sflag==1){
        //                strum();
        //                Sflag=0;
        //            }
        //        }
        update(pos);    
        
        usbIfaceReadBytes(&usb);
        if(midiParserHasMsg(&parser,&msg)){
            mGreenTOGGLE;
            usbIfacePrintf(&usb, "status  %02x\n",msg.status);
            usbIfacePrintf(&usb, "channel %02x\n",msg.channel);
            usbIfacePrintf(&usb, "data[0] %02x\n",msg.data[0]);
            usbIfacePrintf(&usb, "data[1] %02x\n\n",msg.data[1]);
            if(msg.channel == INSTRUMENT_CHANNEL || msg.channel == BOTH_CHANNEL) {
              if(msg.status==NOTE_ON){
                  strum();
                  Sflag=1;
                  switch(msg.data[0]){
                      case 40:
                        pos = E2;
                        break;
                      case 41:
                        pos = F2;
                        break;
                      case 42:
                        pos = FS2;
                        break;
                      case 43:
                        pos = G2;
                        break;
                      case 44:
                        pos = GS2;
                        break;
                      case 45:
                        pos = A2;
                        break;
                      case 46:
                        pos = AS2;
                        break;
                      case 47:
                        pos = B2;
                        break;
                      case 48:
                        pos = C3;
                        break;
                      case 49:
                        pos = CS3;
                        break;
                      case 50:
                        pos = D3;
                        break;
                      case 51:
                        pos = DS3;
                        break;
                      case 52:
                        pos = E3;
                        break;
                      case 53:
                        pos = F3;
                        break;
                      case 54:
                        pos = FS3;
                        break;
                      case 55:
                        pos = G3;
                        break;
                      case 56:
                        pos = GS3;
                        break;
                      case 57:
                        pos = A3;
                        break;
                      case 58:
                        pos = AS3;
                        break;
                      case 59:
                        pos = B3;
                        break;
                      case 60:
                        pos = C4;
                        break;
                      default:
                        break;

                    /*
                    case 57:
                        pos=A3;
                        break;
                    case 59:
                        pos=B3;
                        break;
                    case 60:
                        pos=C4;
                        break;
                    case 62:
                        pos=D4;
                        break;
                    case 64:
                        pos=E4;
                        break;
                        pos=F4;
                        break;
                    case 67:
                        pos=G4;
                        break;
                    case 69:
                        pos=A4;
                        break;
                    case 71:
                        pos=B4;
                        break;
                    case 72:
                        pos=C5;
                        break;
                    default:
                        break;
                    */
                  }
               }
            }
        }
        usbIfaceWriteBytes(&usb);
    }
}
コード例 #6
0
ファイル: main.c プロジェクト: kentdev/m4-text-editor
int main (void)
{
    mInit();
    mBusInit();
    mUSBInit();
    
    mWhiteOFF;
    mRedOFF;
    mGreenON;
    
    for (uint8_t i = 0; i < COMMAND_SIZE + 1; i++)
        command_buffer[i] = '\0';  // initialize command buffer
    
    bool sd_initialized = false;
    
reconnect:
    while (bDeviceState != CONFIGURED);
    
    sd_initialized = m_sd_init();
    
    mWaitms (1000);
    welcome_screen();
    
    if (!sd_initialized)
        printf ("ERROR: Could not initialize microSD card\r\n");
    
    printf ("> ");
    
    for (;;)
    {
        if (bDeviceState != CONFIGURED)
        {
            goto reconnect;
        }
        
        const int rchar = getchar();
        if (rchar < 0)
            continue;
        
        const char c = (char)rchar;
        
        if (c == '\n' || c == '\r')
        {  // received 'enter'
            printf ("\r\n");
            
            if (sd_initialized)
            {
                process_command();
                
                if (fatal_error)
                    sd_initialized = false;
            }
            else
            {
                if (m_sd_init())
                {
                    fatal_error = false;
                    sd_initialized = true;
                    
                    process_command();
                    
                    if (fatal_error)
                        sd_initialized = false;
                }
                else
                {
                    printf ("ERROR: Could not initialize microSD card: error code %d\r\n", m_sd_error_code);
                }
            }
            
            command_ptr = command_buffer;  // reset the current command length to 0
            
            printf ("> ");
        }
        else if (c == 8 || c == 127)
        {  // received backspace (or delete)
            if (command_ptr > command_buffer)
            {
                command_ptr--;
                
                putchar (27);  // escape
                printf ("[1D");  // move the cursor back 1 character
                putchar (27);
                printf ("[K");  // erase from the cursor position to the end of the line
            }
        }
        else if (c >= 32 && c < 127)
        {  // received a printable character or escape
            if (command_ptr < command_buffer + COMMAND_SIZE)
            {
                *command_ptr = c;
                command_ptr++;
                
                putchar (c);
            }
            else
            {  // out of command space: send bell
                putchar (7);
            }
        }
    }
    
    return 0;
}