My understanding of this isn't the best but if I have this right the lowest function that is hit would be _write so what your saying is I should got though and see what _write gets and convert \n to \r\n when it goes through a stdxxx stream? makes sense.Can't help with the details of what you are doing, but note that the normal practice in this area is that you keep \r only all the way through the C library and only convert to \r\n at the final, lowest-layer step.And then there is puts it only appends a newline to a string and I need newline and carriage return. I can see no way to change this with newlib maybe I'm missing it
So in Unix this isn't happening in the program at all, it's happening in the TTY driver.
In my embedded work on other platforms, everything (printf(), puts() etc) all funnels into a putchar() function and it's putchar() that adds the \n.
In Pico SDK, the \n usually gets added in the pico_stdio driver layer - which is perhaps slightly confusingly named as it sits underneath the C library's stdio support, except to the extent that the C-library gets bypased by PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS. Either way, the \n is being added at the lowest layer common character output just before it gets split to UART/USB/etc.
I do this when reading from stdin
Code:
int read_stdin(){ int iCh = _VBUFFERS.VIDEO_REG.KEYBOARD_RAW_MODE ? get_lastkey().keycode : get_lastkey().character; if (!_VBUFFERS.VIDEO_REG.KEYBOARD_RAW_MODE) { if (iCh == 4) { return EOF; } local_echo(iCh); if(iCh == '\r') { iCh ='\n'; local_echo(iCh); } // [ENTER] returns 13 not 10 } return iCh;}
Code:
int _write(int fd, void* buf, size_t cnt) { if (fd == STDIN_FILENO) { return EOF; } if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { for (size_t i = 0; i < cnt; i++) { Decode_Character(((char *)buf)[i]); // Process each character } return cnt; } fd -= 3; if (PT_FilePool[fd] == NULL) return set_errno(EBADF); size_t ret = 0; FRESULT fr = f_write (PT_FilePool[fd], buf, cnt, &ret); if ( fr != FR_OK ) return fatfs_error(fr); return ret;}
Statistics: Posted by DarkElvenAngel — Thu Dec 12, 2024 6:47 pm