Example #1
0
/* 
	Our window with cursor has got some input
	
	key_cnt == -1 means no input has been taking place at this cursor position
	key_cnt >= 0 means the same key has been pressed one or more times here
*/
void
win_cursor_input(int new_key){
	char c;
	
	if (new_key == CURSOR_LEFT){
		dec_cursor();
		key_cnt = -1;
		last_key = -1;
		timer_stop(&char_tmr);
		return;
	};
	
	if (new_key == CURSOR_RIGHT){
		advance_cursor();
		key_cnt = -1;
		last_key = -1;
		timer_stop(&char_tmr);
		return;
	};
	
	/* A bit tricky. It makes sense to implement this as a kind of delete, i.e. delete the character 
		under the cursor. This only fails if the cursor is at end of text. Then delete the last character.
	*/
	if (new_key == CURSOR_BACKSPACE){
		key_cnt = -1;
		last_key = -1;
		timer_stop(&char_tmr);
		
		del_char(pcursor_win, cursor_pos);
		cursor_pos = min(cursor_pos, pcursor_win->text_len);
		return;	
	};
	
	timer_set(&char_tmr, WAIT_KEY_TIME, 0);				// start auto advance timer	
	/* This is the first time a key is pressed here */
	if (key_cnt < 0){
		key_cnt = 0;
		c = key2char(new_key, 0);
		store_char(pcursor_win, cursor_pos, c);
	} else {
		/* We already entered text at this cursor position */	
		if (new_key == last_key){			// User pressed the same key twice before a time out occured 
			key_cnt++;
			c = key2char(new_key, key_cnt);
			store_char(pcursor_win, cursor_pos, c);
		} else {
		// User pressed a different key, advance to the next cursor position, store new char
			key_cnt = 0;
			c = key2char(new_key, 0);
			advance_cursor();
			store_char(pcursor_win, cursor_pos, c);
		};
	};
	last_key = new_key;		
};
usbMsgLen_t usbFunctionSetup(uchar data[8])
{
  usbRequest_t    *rq = (usbRequest_t*)((void *)data);

    if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* HID class request */
        if(rq->bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */
            /* since we have only one report type, we can ignore the report-ID */
	    static uchar dataBuffer[1];  /* buffer must stay valid when usbFunctionSetup returns */
	    if (tx_available()) {
	      dataBuffer[0] = tx_read();
	      usbMsgPtr = dataBuffer; /* tell the driver which data to return */
	      return 1; /* tell the driver to send 1 byte */
	    } else {
	      // Drop through to return 0 (which will stall the request?)
	    }
        }else if(rq->bRequest == USBRQ_HID_SET_REPORT){
            /* since we have only one report type, we can ignore the report-ID */

	  // TODO: Check race issues?
	  store_char(rq->wIndex.bytes[0], &rx_buffer);

        }
    }else{
        /* ignore vendor type requests, we don't use any */
    }
    return 0;
}
Example #3
0
void USART1_IRQHandler(void)
{
	char c;
	FlagStatus RXNE,TXE;
	RXNE = USART_GetFlagStatus(USART1,USART_FLAG_RXNE);
	if (RXNE == SET)
	{
		c = USART_ReceiveData(USART1);
		store_char(c, &rx_buffer);
	}
	TXE = USART_GetFlagStatus(USART1,USART_FLAG_TXE);
	if (TXE == SET)
	{
		if (tx_buffer.head == tx_buffer.tail)
		{
			USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
		}
		else
		{
			c = tx_buffer.buffer[tx_buffer.tail];
			tx_buffer.tail = (tx_buffer.tail + 1) % SERIAL_BUFFER_SIZE;
			USART_SendData(USART1,c);
		}
	}		
}
Example #4
0
// Shared Interrupt Handler for USART2/Serial1 and USART1/Serial2
// WARNING: This function MUST remain reentrance compliant -- no local static variables etc.
static void HAL_USART_Handler(HAL_USART_Serial serial)
{
    if(USART_GetITStatus(usartMap[serial]->usart_peripheral, USART_IT_RXNE) != RESET)
    {
        // Read byte from the receive data register
        unsigned char c = USART_ReceiveData(usartMap[serial]->usart_peripheral);
        store_char(c, usartMap[serial]->usart_rx_buffer);
    }

    if(USART_GetITStatus(usartMap[serial]->usart_peripheral, USART_IT_TXE) != RESET)
    {
        // Write byte to the transmit data register
        if (usartMap[serial]->usart_tx_buffer->head == usartMap[serial]->usart_tx_buffer->tail)
        {
            // Buffer empty, so disable the USART Transmit interrupt
            USART_ITConfig(usartMap[serial]->usart_peripheral, USART_IT_TXE, DISABLE);
        }
        else
        {
            // There is more data in the output buffer. Send the next byte
            USART_SendData(usartMap[serial]->usart_peripheral, usartMap[serial]->usart_tx_buffer->buffer[usartMap[serial]->usart_tx_buffer->tail++]);
            usartMap[serial]->usart_tx_buffer->tail %= SERIAL_BUFFER_SIZE;
        }
    }
}
//****************************************************************
// Need to return FALSE if we need USB to hold off for awhile
boolean	USBstoreDataRoutine(const byte *buffer, int length)
{
    int	i;
    RXOn();

    // If we have a receive callback defined then repeatedly
    // call it with each character.
    if (Serial.rxIntr != NULL) {
        for (i = 0; i < length; i++) {
            Serial.rxIntr(buffer[i]);
        }
        RXOff();
        return true;
    }

    // Put each byte into the serial recieve buffer
    for (i=0; i<length; i++)
	{
        store_char(buffer[i], &rx_bufferUSB);
	}
    // If there isn't going to be enough space for a whole nother buffer, then return
    // false so USB will NAK and we won't get any more data.
    if (USBSerialBufferFree() < USB_SERIAL_MIN_BUFFER_FREE)
    {
        RXOff();
        return(false);
    }
    else
    {
        RXOff();
        return(true);
    }
}
Example #6
0
void HID_Send(uint8_t * Buffer){
	uint8_t i=0;

	while (Buffer[i]!='\0'){
		store_char(Buffer[i], &tx_buffer_cdc);
		i++;
	}
}
//****************************************************************
boolean	USBstoreDataRoutine(const byte *buffer, int length)
{
unsigned int	ii;

	for (ii=0; ii<length; ii++)
	{
		store_char(buffer[ii], &rx_bufferUSB);
	}
}
Example #8
0
void read_stdin_to_buffer() {
	int c;
	
	while(kbhit()) {
		c = getch();
		if(c == 0x03) { captureSigInt(0); }
		
		store_char((unsigned char)c, &rx_buffer);
	}
}
Example #9
0
interrupt void uart_rx_isr(void)
{
	unsigned char c = SciaRegs.SCIRXBUF.all;
	store_char(c, &rx_buffer);

	SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;   // Clear Overflow flag
    SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;   // Clear Interrupt flag

	PieCtrlRegs.PIEACK.all|=0x100;       // Issue PIE ack

}
Example #10
0
// Shared Interrupt Handler for USART2/Serial1 and USART1/Serial2
// WARNING: This function MUST remain reentrance compliant -- no local static variables etc.
static void HAL_USART_Handler(HAL_USART_Serial serial)
{
  if(USART_GetITStatus(usartMap[serial]->usart_peripheral, USART_IT_RXNE) != RESET)
  {
    // Read byte from the receive data register
    uint16_t c = USART_ReceiveData(usartMap[serial]->usart_peripheral);
    // Remove parity bits from data
    c &= HAL_USART_Calculate_Data_Bits_Mask(usartMap[serial]->usart_config);
    store_char(c, usartMap[serial]->usart_rx_buffer);
  }

  uint8_t noecho = (usartMap[serial]->usart_config & (SERIAL_HALF_DUPLEX | SERIAL_HALF_DUPLEX_NO_ECHO)) == (SERIAL_HALF_DUPLEX | SERIAL_HALF_DUPLEX_NO_ECHO);

  if(USART_GetITStatus(usartMap[serial]->usart_peripheral, USART_IT_TC) != RESET) {
    if (noecho) {
      USART_ITConfig(usartMap[serial]->usart_peripheral, USART_IT_TC, DISABLE);
      HAL_USART_Configure_Transmit_Receive(serial, 0, 1);
    }
  }

  if(USART_GetITStatus(usartMap[serial]->usart_peripheral, USART_IT_TXE) != RESET)
  {
    // Write byte to the transmit data register
    if (usartMap[serial]->usart_tx_buffer->head == usartMap[serial]->usart_tx_buffer->tail)
    {
      // Buffer empty, so disable the USART Transmit interrupt
      USART_ITConfig(usartMap[serial]->usart_peripheral, USART_IT_TXE, DISABLE);
      if (noecho) {
        USART_ITConfig(usartMap[serial]->usart_peripheral, USART_IT_TC, ENABLE);
      }
    }
    else
    {
      if (noecho) {
        HAL_USART_Configure_Transmit_Receive(serial, 1, 0);
      }

      // There is more data in the output buffer. Send the next byte
      USART_SendData(usartMap[serial]->usart_peripheral,
        usartMap[serial]->usart_tx_buffer->buffer[usartMap[serial]->usart_tx_buffer->tail++]);
      usartMap[serial]->usart_tx_buffer->tail %= SERIAL_BUFFER_SIZE;
    }
  }
}
Example #11
0
void UARTIntHandler(void) {
    unsigned long ulStatus;
    long UART_character = 0;
    // Get the interrupt status.
    //
    ulStatus = UARTIntStatus(UART0_BASE, true);
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART0_BASE, ulStatus);
    // Loop while there are characters in the receive FIFO.
    //
    while(UARTCharsAvail(UART0_BASE)) {
        // Read the next character from the UART and write it back to the UART.
        //
    	//UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE));
        UART_character = UARTCharGetNonBlocking(UART0_BASE);
        store_char(UART_character);
    }
}
Example #12
0
//*******************************************************************************************
// UART 3 interrupt handler
// it is set at priority level 2
//*******************************************************************************************
void __ISR(_UART3_VECTOR, ipl2) IntUart3Handler(void)
{
unsigned char theChar;

	// Is this an RX interrupt?
	if (mU3RXGetIntFlag())
	{
		theChar	=	ReadUART3();
		store_char(theChar, &rx_buffer3);

		// Clear the RX interrupt Flag (must be AFTER the read)
	    mU3RXClearIntFlag();
	}

	// We don't care about TX interrupt
	if ( mU3TXGetIntFlag() )
	{
		mU3TXClearIntFlag();
	}
}
Example #13
0
//*******************************************************************************************
// UART 2B interrupt handler
// it is set at priority level 2
//*******************************************************************************************
void __ISR(_UART_2B_VECTOR, ipl2) IntUart2BHandler(void)
{
unsigned char theChar;

	// Is this an RX interrupt?
	if (mU2BRXGetIntFlag())
	{

		theChar	=	U2BRXREG;
		store_char(theChar, &rx_buffer2B);

		// Clear the RX interrupt Flag (must be AFTER the read)
	    mU2BRXClearIntFlag();
	}

	// We don't care about TX interrupt
	if ( mU2BTXGetIntFlag() )
	{
		mU2BTXClearIntFlag();
	}
}
Example #14
0
void read_stdin_to_buffer() {
	int c;
	while((c = getchar()) != -1) {
		store_char((unsigned char)c, &rx_buffer);
	}
}
Example #15
0
/* ----------------- */
show_font()
{
int off, key, w, h, ww, wh, dummy;
register int i, hg, eo;
OBJECT *show_form;
int sx, sy, sw, sh, c_xy[4], eff = NORMAL, f_sld;
int sk = 0;

menu_bar(menu_adr, FALSE);
store_char();

inst_font(&show_head);
vsf_interior(vdi_handle, 0);

for (i = 0; i < 14 && show_head.skewmask != skew[i]; i++);
if (i < 14)
	sk = i;
else
	sk = 6;
	
rsrc_gaddr(ROOT, SHW_FLD, &show_form);

form_center(show_form, &sx, &sy, &sw, &sh);
strcpy(show_form[SHW_NAM].ob_spec, font_back[FONTNAME].ob_spec);
strcpy(show_form[SHW_DEF].ob_spec, font_back[CHAR_DEF].ob_spec);

show_form[BOLD].ob_state &= ~SELECTED;
show_form[ITALIC].ob_state &= ~SELECTED;
show_form[LIGHT].ob_state &= ~SELECTED;
show_form[OUTL].ob_state &= ~SELECTED;
show_form[UNDERL].ob_state &= ~SELECTED;

show_form[KR_UP].ob_state |= DISABLED;
show_form[KR_DWN].ob_state |= DISABLED;
show_form[UL_UP].ob_state |= DISABLED;
show_form[UL_DWN].ob_state |= DISABLED;

hg = show_head.top * 2;
make_rasc((long)hg, 100L, ((TEDINFO *)show_form[SHW_TG].ob_spec)->te_ptext);

off = akt_char;
set_aktshw(&f_sld, off, show_form);

make_rasc((long)show_head.formheight, 10L, show_form[SHW_HGHT].ob_spec);

objc_draw(show_form, ROOT, MAX_DEPTH, sx, sy, sw, sh);

objc_offset(show_form, SHW_WIND, &c_xy[0], &c_xy[1]);
c_xy[2] = c_xy[0] + show_form[SHW_WIND].ob_width - 1;
c_xy[3] = c_xy[1] + show_form[SHW_WIND].ob_height - 1;

do
	{
	make_fontscreen(off, hg, c_xy, eff);

	eo = form_do(show_form, 0) & 0x7FFF;

	if (!(show_form[eo].ob_state & DISABLED))
		switch(eo)
			{
			case BOLD:
				if (show_form[BOLD].ob_state & SELECTED)
					eff |= 1;
				else
					eff &= ~1;
				break;
	
			case LIGHT:
				if (show_form[LIGHT].ob_state & SELECTED)
					eff |= 2;
				else
					eff &= ~2;
				break;
	
			case ITALIC:
				if (show_form[ITALIC].ob_state & SELECTED)
					{
					eff |= 4;
					show_form[KR_UP].ob_state &= ~DISABLED;
					show_form[KR_DWN].ob_state &= ~DISABLED;
					}
				else
					{
					eff &= ~4;
					show_form[KR_UP].ob_state |= DISABLED;
					show_form[KR_DWN].ob_state |= DISABLED;
					}
				objc_draw(show_form, SHW_PARA, MAX_DEPTH, sx, sy, sw, sh);
				break;
	
			case UNDERL:
				if (show_form[UNDERL].ob_state & SELECTED)
					{
					eff |= 8;
					show_form[UL_UP].ob_state &= ~DISABLED;
					show_form[UL_DWN].ob_state &= ~DISABLED;
					}
				else
					{
					eff &= ~8;
					show_form[UL_UP].ob_state |= DISABLED;
					show_form[UL_DWN].ob_state |= DISABLED;
					}
				objc_draw(show_form, SHW_PARA, MAX_DEPTH, sx, sy, sw, sh);
				break;
	
			case OUTL:
				if (show_form[OUTL].ob_state & SELECTED)
					eff |= 16;
				else
					eff &= ~16;
				break;
	
			case TG_UP:
				if (hg < show_head.top * 2)
					do
						{
						hg++;
						}while(hg == show_head.top);
				make_rasc((long)hg, 100L, ((TEDINFO *)show_form[SHW_TG].ob_spec)->te_ptext);
				objc_draw(show_form, SHW_TG, MAX_DEPTH, sx, sy, sw, sh);
				break;
	
			case TG_DWN:
				if (hg > 3)
					do
						{
						hg--;
						}while(hg == show_head.top);
				make_rasc((long)hg, 100L, ((TEDINFO *)show_form[SHW_TG].ob_spec)->te_ptext);
				objc_draw(show_form, SHW_TG, MAX_DEPTH, sx, sy, sw, sh);
				break;
	
			case UL_DWN:
				if (show_head.underlinemask < 10)
					show_head.underlinemask++;
				break;
				
			case UL_UP:
				if (show_head.underlinemask > 0)
					show_head.underlinemask--;
				break;
	
			case KR_DWN:
				if (sk < 13)
					show_head.skewmask = skew[++sk];
				break;
				
			case KR_UP:
				if (sk > 0)
					show_head.skewmask = skew[--sk];
				break;
	
			case SHW_UP:
				if (off > 0)
					off--;
				set_aktshw(&f_sld, off, show_form);
				objc_draw(show_form, SHW_CBKG, MAX_DEPTH, sx, sy, sw, sh);
				objc_draw(show_form, SHW_INFO, MAX_DEPTH, sx, sy, sw, sh);
				break;
	
			case SHW_DWN:
				if (off < 255)
					off++;
				set_aktshw(&f_sld, off, show_form);
				objc_draw(show_form, SHW_CBKG, MAX_DEPTH, sx, sy, sw, sh);
				objc_draw(show_form, SHW_INFO, MAX_DEPTH, sx, sy, sw, sh);
				break;
				
			default:
				show_form[eo].ob_state &= ~SELECTED;
			}
				
	}while(eo != SHW_END);

deinst_font();

menu_bar(menu_adr, TRUE);
objc_change(font_back, MARKER, 0, fx, fy, fw, fh, NORMAL, TRUE);
form_dial(FMD_FINISH, 0, 0, 0, 0, sx, sy, sw, sh);

show_character();
show_ccharacter();
draw_edit();
objc_change(font_back, MARKER, 0, fx, fy, fw, fh, SELECTED, TRUE);
}
static inline void uart_rx_isr(void)
{
	unsigned char c = USCI_A_UART_receiveData(USCI_A1_BASE);
	store_char(c, &_rxBuf);
}
size_t DigiUSBDevice::write(byte c) {
  /*
   */
  return store_char(c, _tx_buffer);
}
void CDCSerial::store(char c){
	store_char(c, &rx_buffer_cdc);
}
Example #19
0
size_t TwiscnUSBDevice::write(byte c) {
    return store_char(c, _tx_buffer);
}
Example #20
0
void MarlinSerial::checkRx(void) {
  if (TEST(M_UCSRxA, M_RXCx)) {
    uint8_t c  =  M_UDRx;
    store_char(c);
  }
}
Example #21
0
int
frec_proc_heur(heur_t *h, const wchar_t *regex, size_t len, int cflags)
{
	int errcode;
	parser_state state;

	errcode = init_state(&state, regex, len, cflags);
	if (errcode != REG_OK)
		goto err;

	DEBUG_PRINT("enter");

	/*
	 * Process the pattern char-by-char.
	 *
	 * state.procidx: position in regex
	 * state.heur: buffer for the fragment being extracted
	 * state.heurpos: buffer position
	 */
	for (state.procidx = 0; state.procidx < state.len; state.procidx++) {
		switch (state.regex[state.procidx]) {

		/*
		 * BRE/ERE: Bracketed expression ends the segment or the
		 * brackets are treated as normal if at least the opening
		 * bracket is escaped.
		 */
		case L'[':
			if (state.escaped) {
				store_char(&state);
				continue;
			} else {
				if (parse_set(&state) == REG_BADPAT)
					return REG_BADPAT;
				state.tlen = (state.tlen == -1) ? -1 : state.tlen + 1;
				errcode = end_segment(&state, false);
				if (errcode != REG_OK)
					goto err;
			}
			continue;

		/*
		 * If a repetition marker, erases the repeting character
		 * and terminates the segment, otherwise treated as a normal
		 * character.
		 * BRE: repetition marker if ESCAPED.
		 * ERE: repetition marker if NOT ESCAPED.
		 */
		case L'{':
			/* Be more permissive at the beginning of the pattern */
			if (state.escaped && (state.procidx == 1)) {
				store_char(&state);
				continue;
			} else if (state.procidx == 0) {
				store_char(&state);
				continue;
			}

			if (state.escaped ^ state.ere) {
				drop_last_char(&state);
				parse_unit(&state, L'{', L'}');
				errcode = end_segment(&state, true);
				if (errcode != REG_OK)
					goto err;
			} else {
				store_char(&state);
				continue;
			}
			continue;

		/*
		 * Terminates the current segment if used for a subexpression,
		 * otherwise treated as a normal character.
		 * BRE: subexpression if ESCAPED.
		 * ERE: subexpression if NOT ESCAPED.
		 */
		case L'(':
			if (state.escaped ^ state.ere) {
				parse_unit(&state, L'(', L')');
				errcode = end_segment(&state, true);
				if (errcode != REG_OK)
					goto err;
			} else {
				store_char(&state);
				continue;
			}
			continue;

		/*
		 * Sets escaped flag.
		 * Escaped escape is treated as a normal character.
		 * (This is also the GNU behaviour.)
		 */
		case L'\\':
			if (state.escaped) {
				store_char(&state);
				continue;
			} else
				state.escaped = true;
			continue;

		/*
		 * BRE: If not the first character and not escaped, erases the
		 * last character and terminates the segment.
		 * Otherwise treated as a normal character.
		 * ERE: Skipped if first character (GNU), rest is like in BRE.
		 */
		case L'*':
			/* Be more permissive at the beginning of the pattern */
			if (state.escaped || (!state.ere && (state.procidx == 0))) {
				store_char(&state);
				continue;
			} else {
				drop_last_char(&state);
				errcode = end_segment(&state, true);
				if (errcode != REG_OK)
					goto err;
			}
			continue;

		/*
		 * BRE: it is a normal character, behavior is undefined
		 * when escaped.
		 * ERE: it is special unless escaped. Terminate segment
		 * when not escaped. Last character is not removed because it
		 * must occur at least once. It is skipped when first
		 * character (GNU).
		 */
		case L'+':
			/* Be more permissive at the beginning of the pattern */
			if (state.ere && (state.procidx == 0))
				continue;
			else if (state.ere ^ state.escaped) {
				errcode = end_segment(&state, true);
				if (errcode != REG_OK)
					goto err;
			} else {
				store_char(&state);
				continue;
			}
			continue;

		/*
		 * BRE: it is a normal character, behavior is undefined
		 * when escaped.
		 * ERE: it is special unless escaped. Terminate segment
		 * when not escaped. Last character is removed. Skipped when
		 * first character (GNU).
		 */
		case L'?':
			/* Be more permissive at the beginning of the pattern */
			if (state.ere && (state.procidx == 0))
				continue;
			if (state.ere ^ state.escaped) {
				drop_last_char(&state);
				errcode = end_segment(&state, true);
				if (errcode != REG_OK)
					goto err;
			} else {
				store_char(&state);
				continue;
			}
			continue;

		/*
		 * BRE: it is a normal character, behavior is undefined
		 * when escaped.
		 * ERE: alternation marker; unsupported.
		 */
		case L'|':
			if (state.ere ^ state.escaped) {
				errcode = REG_BADPAT;
				goto err;
			} else {
				store_char(&state);
				continue;
			}
			continue;

		/*
		 * BRE/ERE: matches any single character; normal character
		 * if escaped.
		 */
		case L'.':
			if (state.escaped) {
				store_char(&state);
				continue;
			} else {
				state.has_dot = true;
				state.tlen = (state.tlen == -1) ? -1 : state.tlen + 1;
				errcode = end_segment(&state, false);
				if (errcode != REG_OK)
					goto err;
			}
			continue;

		case L'\n':
			state.has_lf = true;
			store_char(&state);
			continue;

		/*
		 * If escaped, terminates segment.
		 * Otherwise adds current character to the current segment
		 * by copying it to the temporary space.
		 */
		default:
			if (state.escaped) {
				if (state.regex[state.procidx] == L'n') {
					state.has_lf = true;
					store(&state, L'\n');
					continue;
				}
				errcode = end_segment(&state, true);
				if (errcode != REG_OK)
					goto err;
			} else {
				store_char(&state);
				continue;
			}
			continue;
		}
	}

	if (state.heurpos > 0) {
		errcode = end_segment(&state, false);
		if (errcode != REG_OK)
			goto err;
	}

	h->heur = malloc(sizeof(fastmatch_t));
	if (!h->heur) {
		errcode = REG_ESPACE;
		goto err;
	}

	errcode = fill_heuristics(&state, h);
	if (errcode != REG_OK)
		goto err;

	errcode = REG_OK;

err:
	if ((errcode != REG_OK) && (h->heur != NULL))
		frec_free_fast(h->heur);

	free_state(&state);
	return (errcode);
}