コード例 #1
0
ファイル: base.c プロジェクト: BrzTit/Bus_Pirate
//get bus pirate ready after first start
//or clean up after any dirty modules
//modules MUST teardown any PPS functions on the CMD_CLEANUP command
void bpInit(void){
	//do this manually so there aren't problems with hardware
	//that has I/O on different ports
	BP_MOSI_DIR=1;
	BP_CLK_DIR=1; 
	BP_MISO_DIR=1;
	BP_CS_DIR=1; 
	BP_AUX0_DIR=1;
	BP_LEDMODE=0; //mode LED OFF
	BP_LEDMODE_DIR=0;
	#ifdef BUSPIRATEV4
		BP_USBLED_OFF();
		BPV4_HWI2CPINS_SETUP();
		BP_BUTTON_SETUP();
		BP_3V3PU_OFF();
		//BP_5VPU_OFF();
		BP_EEPROM_SETUP();
	#endif
	#ifdef BUSPIRATEV1A
		BP_PIN6_DIR=1; //AUX2... unused
		BP_LEDPWR=1; //light power led
		BP_LEDPWR_DIR=0;
	#endif

	BP_AUX_RPOUT = 0;    //remove output from AUX pin (PWM/servo modes)

	bpConfig.busMode=HIZ;

	clearModeConfig(); //reset the mode settings structure
	
	#ifndef BUSPIRATEV1A
		BP_PULLUP_OFF();
	#endif

	BP_VREG_OFF();//disable the VREG

	//setup voltage monitoring on ADC. see hardwarevx.h!
	BP_ADC_PINSETUP();

	//configure the ADC
	AD1CON1bits.SSRC  = 0b111;// SSRC<3:0> = 111 implies internal
								// counter ends sampling and starts
								// converting.
	AD1CSSL = 0;
	AD1CON3 = 0x1F02; // Sample time = 31Tad,
						// Tad = 2 Tcy
	AD1CON2 = 0;
}
コード例 #2
0
ファイル: base.c プロジェクト: BusPirate/Bus_Pirate
void bp_reset_board_state(void) {
  BP_MOSI_DIR = INPUT;
  BP_CLK_DIR = INPUT;
  BP_MISO_DIR = INPUT;
  BP_CS_DIR = INPUT;
  BP_AUX0_DIR = INPUT;
  bp_disable_mode_led();
  bp_enable_usb_led();
#ifdef BUSPIRATEV4
  BPV4_HWI2CPINS_SETUP();
  BP_BUTTON_SETUP();
  bp_disable_3v3_pullup();
  eeprom_initialize();
#endif /* BUSPIRATEv4 */

  /* Detach source from the currently-set AUX pin. */
  BP_AUX_RPOUT = OFF;

  bus_pirate_configuration.bus_mode = BP_HIZ;
  clear_mode_configuration();
  bp_disable_pullup();
  bp_disable_voltage_regulator();
  bp_adc_pin_setup();

  /* Configure the ADC. */

  /* Enable automatic sample conversion. */
  AD1CON1bits.SSRC = 0b111;

  /*
   * AD1CSSL : A/D INPUT SCAN SELECT REGISTER
   *
   * MSB
   * 0--0000000000000
   * |  |||||||||||||
   * |  +++++++++++++-- CSSL{12:0}: Omit A/D input pins from scan.
   * +----------------- CSSL15:     Band gap voltage reference not scanned.
   */
  AD1CSSL = 0x0000;

  /*
   * AD1CON3 : A/D CONTROL REGISTER 3
   *
   * MSB
   * 0--1111100000010
   * |  |||||||||||||
   * |  |||||++++++++-- ADCS: A/D conversion clock is 3 * Tcy.
   * |  +++++---------- SAMC: Sample time is 31 * Tad (Tad = 3 * Tcy).
   * +----------------- ADRC: Clock is derived from system clock.
   */
  AD1CON3 = 0x1F02;

  /*
   * AD1CON2 : A/D CONTROL REGISTER 2
   *
   * MSB
   * 000--0--x-000000
   * |||  |    ||||||
   * |||  |    |||||+-- ALTS:  Use MUX A input settings.
   * |||  |    ||||+--- BUFM:  Buffer is one single 16-bits word.
   * |||  |    ++++---- SMPI:  Interrupt on each sample conversion completion.
   * |||  +------------ CSCNA: Do not scan inputs.
   * +++--------------- VCFG:  VR+ is AVdd and VR- is AVss.
   */
  AD1CON2 = 0x0000;
}