Skip to content

Instantly share code, notes, and snippets.

View AlexanderSavochkin's full-sized avatar

Alexander Savochkin AlexanderSavochkin

  • Greater Seattle Area
View GitHub Profile
@AlexanderSavochkin
AlexanderSavochkin / Simple matrix class with LU decomposition.cpp
Created July 25, 2023 22:38
Simple matrix class with LU decomposition
#pragma once
#include <tuple>
using std::tuple;
using std::make_tuple;
template<typename T, int m, int n>
class DenseMatrix
{
@AlexanderSavochkin
AlexanderSavochkin / uart_handler.c
Created November 21, 2016 08:04
sam3x8e UART interrupt handler stub
// IT handlers
void UART_Handler(void)
{
uint32_t status = UART->UART_SR;
//Did we receive new byte?
if ((status & UART_SR_RXRDY) == UART_SR_RXRDY)
{
//Read new byte from UART_RHR
@AlexanderSavochkin
AlexanderSavochkin / polling_loop.c
Created November 20, 2016 17:52
Пример организации поллинга UART в sam3x8e
...
while (1)
{
//Если получили очередной байт из UART - прочитаем его в переменную received_data
if ((UART->UART_SR & UART_SR_RXRDY) == UART_SR_RXRDY )
{
uint32_t received_data = UART->UART_RHR;
...
}
//Если готовы отправить очередной байт (зранится в data_to_transmit) через UART - запишем в регистр UART_THR
@AlexanderSavochkin
AlexanderSavochkin / polling_loop.c
Created November 20, 2016 17:52
Пример организации поллинга UART в sam3x8e
...
while (1)
{
//Если получили очередной байт из UART - прочитаем его в переменную received_data
if ((UART->UART_SR & UART_SR_RXRDY) == UART_SR_RXRDY )
{
uint32_t received_data = UART->UART_RHR;
...
}
//Если готовы отправить очередной байт (зранится в data_to_transmit) через UART - запишем в регистр UART_THR
@AlexanderSavochkin
AlexanderSavochkin / setup_uart.c
Created November 20, 2016 08:24
Example of sam3x8e UART initialization
void setupUART()
{
PIO_Configure(PIOA, PIO_PERIPH_A,PIO_PA8A_URXD|PIO_PA9A_UTXD, PIO_DEFAULT);
/* Enable the pull up on the Rx and Tx pin */
PIOA->PIO_PUER = PIO_PA8A_URXD | PIO_PA9A_UTXD;
/*Включаем UART, подавая на него тактирование*/
pmc_enable_periph_clk(ID_UART);
@AlexanderSavochkin
AlexanderSavochkin / component_usart.h
Created November 19, 2016 07:55
Usart structure from libsam headers
...
typedef struct {
WoReg US_CR; /**< \brief (Usart Offset: 0x0000) Control Register */
RwReg US_MR; /**< \brief (Usart Offset: 0x0004) Mode Register */
WoReg US_IER; /**< \brief (Usart Offset: 0x0008) Interrupt Enable Register */
WoReg US_IDR; /**< \brief (Usart Offset: 0x000C) Interrupt Disable Register */
RoReg US_IMR; /**< \brief (Usart Offset: 0x0010) Interrupt Mask Register */
RoReg US_CSR; /**< \brief (Usart Offset: 0x0014) Channel Status Register */
RoReg US_RHR; /**< \brief (Usart Offset: 0x0018) Receiver Holding Register */
WoReg US_THR; /**< \brief (Usart Offset: 0x001C) Transmitter Holding Register */
@AlexanderSavochkin
AlexanderSavochkin / component_uart.h
Created November 19, 2016 07:52
Uart structure from libsam headers
...
typedef struct {
WoReg UART_CR; /**< \brief (Uart Offset: 0x0000) Control Register */
RwReg UART_MR; /**< \brief (Uart Offset: 0x0004) Mode Register */
WoReg UART_IER; /**< \brief (Uart Offset: 0x0008) Interrupt Enable Register */
WoReg UART_IDR; /**< \brief (Uart Offset: 0x000C) Interrupt Disable Register */
RoReg UART_IMR; /**< \brief (Uart Offset: 0x0010) Interrupt Mask Register */
RoReg UART_SR; /**< \brief (Uart Offset: 0x0014) Status Register */
RoReg UART_RHR; /**< \brief (Uart Offset: 0x0018) Receive Holding Register */
WoReg UART_THR; /**< \brief (Uart Offset: 0x001C) Transmit Holding Register */
@AlexanderSavochkin
AlexanderSavochkin / main.c
Last active July 4, 2018 23:25
Simple LED blink on Arduino Due board
#include "due_sam3x.init.h"
int main(void)
{
/* The general init (clock, libc, watchdog disable) */
init_controller();
PIO_Configure(PIOB, PIO_OUTPUT_1, PIO_PB27, PIO_DEFAULT);
while(1)
@AlexanderSavochkin
AlexanderSavochkin / elastic.lua
Created August 31, 2016 05:00 — forked from chsasank/elastic.lua
Elastic transformation/deformation of an image in Torch
require 'image'
function ElasticTransform(img, alpha, sigma)
--[[
Parameters
----------
img: Tensor of size KxHxW
Image on which elastic transformation have to be applied
alpha: number
Intensity of the transformation
glm::mat4 MVP = Projection * View * mechanicalModel.getOrientation() * glm::scale(glm::mat4(1.0f), vec3(1.0, 1.73, 2.24));