Skip to content

Commit

Permalink
modify to sipeed dan dock
Browse files Browse the repository at this point in the history
  • Loading branch information
xelll committed Dec 17, 2018
1 parent de62661 commit 52b7bb8
Show file tree
Hide file tree
Showing 20 changed files with 1,230 additions and 805 deletions.
19 changes: 19 additions & 0 deletions brun.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

K210_BIN_PATH=`pwd`/build

#here should set to yours
BRUN_SCRIPT_PATH=/home/xel/K210/pyScript

bin_file=$K210_BIN_PATH"/"$1".bin"

echo $bin_file

cd $BRUN_SCRIPT_PATH

if [ ! -n "$2" ] ;then
python3 isp.py -b 115200 $bin_file -d /dev/ttyUSB0
else
python3 isp.py -b 115200 $bin_file -d $2
fi

22 changes: 22 additions & 0 deletions brun_auto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

if [ ! -n "$1" ] ;then
echo "you have to select a Bin File!"
exit
fi

K210_BIN_PATH=`pwd`/build
BRUN_SCRIPT_PATH=/home/xel/K210/pyScript

bin_file=$K210_BIN_PATH"/"$1".bin"

echo $bin_file

cd $BRUN_SCRIPT_PATH

if [ ! -n "$2" ] ;then
python3 kflash.py -b 2000000 $bin_file -p /dev/ttyUSB0
else
python3 kflash.py -b 1000000 $bin_file -p $2
fi

2 changes: 2 additions & 0 deletions gdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/xel/kendryte-toolchain-8.2/bin/riscv64-unknown-elf-gdb -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333" -ex "monitor reset halt" -ex "load" $1

23 changes: 19 additions & 4 deletions lib/drivers/dvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "sysctl.h"
#include <math.h>

volatile dvp_t* const dvp = (volatile dvp_t*)DVP_BASE_ADDR;
volatile dvp_t *const dvp = (volatile dvp_t *)DVP_BASE_ADDR;
static uint8_t g_sccb_reg_len = 8;

static void mdelay(uint32_t ms)
Expand Down Expand Up @@ -49,7 +49,7 @@ uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate)
uint32_t tmp;
uint32_t v_sccb_freq = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1);
uint16_t v_period_clk_cnt = round(v_sccb_freq / clk_rate / 2.0);
if(v_period_clk_cnt > 255)
if (v_period_clk_cnt > 255)
{
return 0;
}
Expand Down Expand Up @@ -116,7 +116,7 @@ uint8_t dvp_sccb_receive_data(uint8_t dev_addr, uint16_t reg_addr)

dvp_sccb_start_transfer();

return (uint8_t) DVP_SCCB_RDATA_BYTE(dvp->sccb_cfg);
return (uint8_t)DVP_SCCB_RDATA_BYTE(dvp->sccb_cfg);
}

static void dvp_reset(void)
Expand Down Expand Up @@ -145,6 +145,22 @@ void dvp_init(uint8_t reg_len)
dvp_reset();
}

uint32_t dvp_set_xclk_rate(uint32_t xclk_rate)
{
uint32_t v_apb1_clk = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1);
uint32_t v_period;
if (v_apb1_clk > xclk_rate * 2)
v_period = round(v_apb1_clk / (xclk_rate * 2.0)) - 1;
else
v_period = 0;
if (v_period > 255)
v_period = 255;
dvp->cmos_cfg &= (~DVP_CMOS_CLK_DIV_MASK);
dvp->cmos_cfg |= DVP_CMOS_CLK_DIV(v_period) | DVP_CMOS_CLK_ENABLE;
dvp_reset();
return v_apb1_clk / ((v_period + 1) * 2);
}

void dvp_set_image_format(uint32_t format)
{
uint32_t tmp;
Expand Down Expand Up @@ -278,4 +294,3 @@ void dvp_set_output_enable(dvp_output_mode_t index, int enable)
dvp->dvp_cfg &= ~DVP_CFG_DISPLAY_OUTPUT_ENABLE;
}
}

103 changes: 53 additions & 50 deletions lib/drivers/include/dvp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif

/* clang-format off */
/* clang-format off */
/**
* @brief DVP object
*/
Expand Down Expand Up @@ -94,118 +95,118 @@ typedef struct _dvp
#define DVP_STS_DVP_EN_WE 0x00020000U
#define DVP_STS_SCCB_EN 0x01000000U
#define DVP_STS_SCCB_EN_WE 0x02000000U
/* clang-format on */
/* clang-format on */

typedef enum _dvp_output_mode
{
DVP_OUTPUT_AI,
DVP_OUTPUT_DISPLAY,
} dvp_output_mode_t;
typedef enum _dvp_output_mode
{
DVP_OUTPUT_AI,
DVP_OUTPUT_DISPLAY,
} dvp_output_mode_t;

/**
/**
* @brief DVP object instance
*/
extern volatile dvp_t* const dvp;
extern volatile dvp_t *const dvp;

/**
/**
* @brief Initialize DVP
*/
void dvp_init(uint8_t reg_len);
void dvp_init(uint8_t reg_len);

/**
/**
* @brief Set image format
*
* @param[in] format The image format
*/
void dvp_set_image_format(uint32_t format);
void dvp_set_image_format(uint32_t format);

/**
/**
* @brief Set image size
*
* @param[in] width The width of image
* @param[in] height The height of image
*/
void dvp_set_image_size(uint32_t width, uint32_t height);
void dvp_set_image_size(uint32_t width, uint32_t height);

/**
/**
* @brief Set the address of RGB for AI
*
* @param[in] r_addr The R address of RGB
* @param[in] g_addr The G address of RGB
* @param[in] b_addr The B address of RGB
*/
void dvp_set_ai_addr(uint32_t r_addr, uint32_t g_addr, uint32_t b_addr);
void dvp_set_ai_addr(uint32_t r_addr, uint32_t g_addr, uint32_t b_addr);

/**
/**
* @brief Set the address of RGB for display
*
* @param[in] r_addr The R address of RGB
* @param[in] g_addr The G address of RGB
* @param[in] b_addr The B address of RGB
*/
void dvp_set_display_addr(uint32_t addr);
void dvp_set_display_addr(uint32_t addr);

/**
/**
* @brief The frame start transfer
*/
void dvp_start_frame(void);
void dvp_start_frame(void);

/**
/**
* @brief The DVP convert start
*/
void dvp_start_convert(void);
void dvp_start_convert(void);

/**
/**
* @brief The DVP convert finish
*/
void dvp_finish_convert(void);
void dvp_finish_convert(void);

/**
/**
* @brief Get the image data
*
* @note The image data stored in the address of RGB
*/
void dvp_get_image(void);
void dvp_get_image(void);

/**
/**
* @brief Use SCCB write register
*
* @param[in] dev_addr The device address
* @param[in] reg_addr The register address
* @param[in] reg_data The register data
*/
void dvp_sccb_send_data(uint8_t dev_addr, uint16_t reg_addr, uint8_t reg_data);
void dvp_sccb_send_data(uint8_t dev_addr, uint16_t reg_addr, uint8_t reg_data);

/**
/**
* @brief Use SCCB read register
*
* @param[in] dev_addr The device address
* @param[in] reg_addr The register address
*
* @return The register value
*/
uint8_t dvp_sccb_receive_data(uint8_t dev_addr, uint16_t reg_addr);
uint8_t dvp_sccb_receive_data(uint8_t dev_addr, uint16_t reg_addr);

/**
/**
* @brief Enable dvp burst
*/
void dvp_enable_burst(void);
void dvp_enable_burst(void);

/**
/**
* @brief Disable dvp burst
*/
void dvp_disable_burst(void);
void dvp_disable_burst(void);

/**
/**
* @brief Enable or disable dvp interrupt
*
* @param[in] interrupt Dvp interrupt
* @param[in] status 0:disable 1:enable
*
*/
void dvp_config_interrupt(uint32_t interrupt, uint8_t enable);
void dvp_config_interrupt(uint32_t interrupt, uint8_t enable);

/**
/**
* @brief Get dvp interrupt status
*
* @param[in] interrupt Dvp interrupt
Expand All @@ -215,43 +216,45 @@ void dvp_config_interrupt(uint32_t interrupt, uint8_t enable);
* - 0 false
* - 1 true
*/
int dvp_get_interrupt(uint32_t interrupt);
int dvp_get_interrupt(uint32_t interrupt);

/**
/**
* @brief Clear dvp interrupt status
*
* @param[in] interrupt Dvp interrupt
*
*/
void dvp_clear_interrupt(uint32_t interrupt);
void dvp_clear_interrupt(uint32_t interrupt);

/**
/**
* @brief Enable dvp auto mode
*/
void dvp_enable_auto(void);
void dvp_enable_auto(void);

/**
/**
* @brief Disable dvp auto mode
*/
void dvp_disable_auto(void);
void dvp_disable_auto(void);

/**
/**
* @brief Dvp ouput data enable or not
*
* @param[in] index 0:AI, 1:display
* @param[in] enable 0:disable, 1:enable
*
*/
void dvp_set_output_enable(dvp_output_mode_t index, int enable);
void dvp_set_output_enable(dvp_output_mode_t index, int enable);

/**
/**
* @brief Set sccb clock rate
*
* @param[in] clk_rate Sccb clock rate
*
* @return The real sccb clock rate
*/
uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate);
uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate);

uint32_t dvp_set_xclk_rate(uint32_t xclk_rate);

#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

cd ./build
cmake .. -DPROJ=$1 -DTOOLCHAIN=/home/xel/kendryte-toolchain-8.2/bin && make
Binary file added openmv_sipeed_m1_dock.bin
Binary file not shown.
1 change: 1 addition & 0 deletions src/openmv/src/micropython/ports/k210-standalone/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ MODULES_SRC_C= \
$(MPY_MOD_PATH)/machine/machine_timer.c\
$(MPY_MOD_PATH)/machine/machine_nt35310.c\
$(MPY_MOD_PATH)/machine/machine_ov5640.c\
$(MPY_MOD_PATH)/machine/machine_ov2640.c\
$(MPY_MOD_PATH)/machine/machine_burner.c\
$(MPY_MOD_PATH)/machine/machine_face_detect.c\
$(MPY_MOD_PATH)/machine/machine_spiflash.c\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
#define INTERFACE_CTL 0xF6

#define DCX_GPIONUM (2)
#define RST_GPIONUM (3)

#define SPI_CHANNEL 0
#define SPI_SLAVE_SELECT 3
Expand All @@ -109,4 +110,3 @@ void tft_write_word(uint32_t *data_buf, uint32_t length, uint32_t flag);
void tft_fill_data(uint32_t *data_buf, uint32_t length);

#endif

Loading

0 comments on commit 52b7bb8

Please sign in to comment.